Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend FFI::Library doesn't extend some methods into module #1529

Closed
deepj opened this issue Dec 16, 2018 · 11 comments
Closed

extend FFI::Library doesn't extend some methods into module #1529

deepj opened this issue Dec 16, 2018 · 11 comments

Comments

@deepj
Copy link

deepj commented Dec 16, 2018

There is no issue under MRI. After initializing the module, TestModule': undefined method 'callback' for TestModule:Module (NoMethodError) exception is occurred. The code below tries to call this method https://www.rubydoc.info/github/ffi/ffi/FFI/Library#callback-instance_method

require 'ffi'

module TestModule
  extend FFI::Library

  callback :g_log_func, [:string, :int, :string, :pointer], :void
end

TestModule

This is a small reproducible example of issue comes from https://github.com/libvips/ruby-vips/blob/428d5c106fb4a64521159c6b0c4f9391eea2eba6/lib/vips.rb#L36

Error:

ruby-ffi.rb:6:in `TestModule': undefined method `callback' for TestModule:Module (NoMethodError)
	from ruby-ffi.rb:3:in `<main>'
@deepj
Copy link
Author

deepj commented Dec 16, 2018

It seems to be similar to #1524

@eregon
Copy link
Member

eregon commented Dec 16, 2018

Our current implementation of FFI (using Truffle NFI) is not complete, so this means we did not implement that method yet.
It's an open question currently whether we can and how to reuse some of the upstream FFI code (we likely wouldn't want a second libffi copy, so using Truffle NFI would be better).

@deepj
Copy link
Author

deepj commented Dec 16, 2018

@eregon Are you sure? Because in case of ruby-vips, the ffi is installed via Bundler, and ruby-vips specs are run via bundle exec rake spec. So I guess, the ffi is used.

@deepj
Copy link
Author

deepj commented Dec 16, 2018

In fact I've seen more issues like undefined method 'callback' due to some issue in extending classes/modules in TruffleRuby.

@eregon
Copy link
Member

eregon commented Dec 16, 2018

@deepj The ffi gem is installed, but it no-ops when require-d: https://github.com/ffi/ffi/blob/0ee4f7931bb56c7d0e11ef66c51711cb59a80bc4/lib/ffi.rb#L12

@deepj
Copy link
Author

deepj commented Dec 16, 2018

@eregon I see, got it.

@eregon
Copy link
Member

eregon commented Jan 22, 2019

This is also an issue for ethon (#1524) and sassc.
Related issue in upstream FFI: ffi/ffi#660
In short, I plan to do a pure-Ruby implementation of FFI using Truffle NFI as backend.

@deepj
Copy link
Author

deepj commented Feb 12, 2019

@eregon @chrisseaton if there would be a chance to move FFI compability forward it could help to run more native gems on TruffleRuby. RC13/14?

@chrisseaton
Copy link
Collaborator

I think we're unlikely to fix this one as fast as the other priority issues, I'm afraid. It's going to be a bit more work.

@chrisseaton
Copy link
Collaborator

I'm going to remove the priority tag on this, as we aren't going to be able to solve it in the next month or so, which is what we're aiming at with priority issues now.

@eregon
Copy link
Member

eregon commented Apr 18, 2019

I fixed this in 59fb511 and added complete support for the FFI, with a pure-Ruby implementation using Truffle NFI.
It will be in the next release (1.0.0-rc16).
Thank you for the report.

@eregon eregon closed this as completed Apr 18, 2019
@eregon eregon added this to the 1.0.0-rc16 milestone Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants