Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Extensions, Windows
    • Labels:
      None
    • Environment:
      jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-06-30 2d1eff7) (Java HotSpot(TM) Client VM 1.6.0_18) [x86-java]
      screenshot gem v 0.0.4
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      This code:

      require 'rubygems'
      require "benchmark"
      require 'win32/screenshot'
      t = "Internet Explorer"
      Benchmark.bmbm do |x|
      x.report("no file") {50.times {Win32::Screenshot.window(t, 0) {}}}
      end

      Eventually crashes [1] in jruby, because a MemoryPointer appears to suddenly be unwritable.

      It succeeds well with MRI.

      Maybe jruby's underlying FFI implementation should do its own memory management, like calling out to malloc and free, to avoid Java's GC (which I assume is the cause [2]).

      -r
      [1] http://gist.github.com/458719
      [2] http://wiki.github.com/ffi/ffi/core-concepts#memory

        Activity

        Show
        Roger Pack added a comment - ref: http://github.com/jarmo/win32screenshot/issues/#issue/2
        Hide
        Roger Pack added a comment -

        also reproducible with this: http://gist.github.com/518855

        Show
        Roger Pack added a comment - also reproducible with this: http://gist.github.com/518855
        Hide
        Wayne Meissner added a comment -

        I wonder if this isn't a calling convention problem. Basically the callback may not be getting setup as :stdcall ... or it is when it isn't supposed to be.

        Try using a FFI::Function (http://ffi.github.com/api/FFI/Function.html) instead of a proc for the callback.
        e.g.

        Win::EnumWindowCallback = FFI::Function.new(:bool, [ :pointer, :long ], { :convention => :stdcall }) do |wnd, param|
          title.clear
          Win.get_window_text(wnd, title, title.size)
          puts "[%03i] Found '%s'" % [ win_count += 1, title.get_string(0) ]
          true
        end
        

        Try with both :convention => :stdcall and :convention => :default and see if it changes anything.

        If it works with :stdcall, it means JRuby is not propagating the :stdcall all the way down to libffi, but should be (somewhat) easy to fix.

        Show
        Wayne Meissner added a comment - I wonder if this isn't a calling convention problem. Basically the callback may not be getting setup as :stdcall ... or it is when it isn't supposed to be. Try using a FFI::Function ( http://ffi.github.com/api/FFI/Function.html ) instead of a proc for the callback. e.g. Win::EnumWindowCallback = FFI::Function.new(:bool, [ :pointer, :long ], { :convention => :stdcall }) do |wnd, param| title.clear Win.get_window_text(wnd, title, title.size) puts "[%03i] Found '%s'" % [ win_count += 1, title.get_string(0) ] true end Try with both :convention => :stdcall and :convention => :default and see if it changes anything. If it works with :stdcall, it means JRuby is not propagating the :stdcall all the way down to libffi, but should be (somewhat) easy to fix.
        Hide
        Roger Pack added a comment - - edited

        it seems to work great with :convention => :stdcall and crash for anything else.

        Looks like a good signature is:

        FFI::Function.new(:bool, [ :long, :pointer ], { :convention => :stdcall }) do |hwnd, param|

        Show
        Roger Pack added a comment - - edited it seems to work great with :convention => :stdcall and crash for anything else. Looks like a good signature is: FFI::Function.new(:bool, [ :long, :pointer ], { :convention => :stdcall }) do |hwnd, param|
        Hide
        Roger Pack added a comment -

        This is still reproducible using the gist.

        Show
        Roger Pack added a comment - This is still reproducible using the gist.

          People

          • Assignee:
            Thomas E Enebo
            Reporter:
            Roger Pack
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: