Subject: [ruby-ffi] Re: cannot define function pointers that take function pointer arguments in jruby struct layout |
From: Aman Gupta |
Date: 9/14/09 3:23 PM |
To: ruby-ffi@googlegroups.com |
On Mon, Sep 14, 2009 at 11:35 AM, Andrea Fazzi <andrea.fazzi@alcacoop.it> wrote:
Excerpts from Aman Gupta's message of lun set 14 11:28:58 +0200 2009:I'm using ffi-swig-generator on: typedef void (*MyCallback) (void *data); typedef struct { void (*member) (MyCallback cb); } MyStruct; which generates: callback(:MyCallback, [ :pointer ], :void) class MyStruct < FFI::Struct layout( :member, callback([ :MyCallback ], :void) ) end This works fine on with ruby-ffi, but on jruby I get: /custom/jruby/lib/ruby/1.8/ffi/types.rb:17:in `find_type': Unable to resolve type 'MyCallback' (FFI::TypeError) from /custom/jruby/lib/ruby/1.8/ffi/library.rb:213:in `find_type' from /custom/jruby/lib/ruby/1.8/ffi/struct.rb:149:in `find_type' from /custom/jruby/lib/ruby/1.8/ffi/library.rb:148:in `callback' from /custom/jruby/lib/ruby/1.8/ffi/library.rb:148:in `each' from /custom/jruby/lib/ruby/1.8/ffi/library.rb:148:in `map' from /custom/jruby/lib/ruby/1.8/ffi/library.rb:148:in `callback'Ruby-FFI support for callback parameters in callbacks was added in rev 8d6045c2305f32929f4da5a28d28397523df0170 Maybe that JRuby still doesn't implement it?
JRuby supports it, just doesn't recognize the callback if its defined before the struct the way ffi-swig-generator does it. The issue is in FFI::Struct#find_type, but I got very confused trying to fix it. If I nest the callback definition inline, it works as expected: class MyStruct < FFI::Struct layout( :member, callback([ callback([ :pointer ], :void) ], :void) ) end
http://twitter.com/remogatto-- Andrea Fazzi @ alca.le.it Follow me on