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

The fiddle gem is broken on truffleruby and jruby #145

Closed
eregon opened this issue Sep 16, 2024 · 2 comments · Fixed by #149
Closed

The fiddle gem is broken on truffleruby and jruby #145

eregon opened this issue Sep 16, 2024 · 2 comments · Fixed by #149

Comments

@eregon
Copy link
Member

eregon commented Sep 16, 2024

Given https://bugs.ruby-lang.org/issues/20309 fiddle will become a bundled gem in Ruby 3.5+.

As a result people will add fiddle to their Gemfile where they previously wouldn't (and so there was no issue).
Unfortunately this leads to failure for example on ffi/ffi#1119:

  • https://github.com/ffi/ffi/actions/runs/10881406447/job/30190278321?pr=1119 JRuby fails when trying to build the C extension
  • TruffleRuby segfaults, probably because the fiddle C extension does something unexpected, and it's completely untested on TruffleRuby. It seems better to use the TruffleRuby Fiddle backend anyway for performance, as it avoids basically going twice through libffi.

I think the best solution for now is to just use fiddle from stdlib on non-CRuby. That's properly tested and working.
IOW, to not build or use the C extension on non-CRuby, similar to how it was done in ruby/stringio#71 or ruby/strscan#35

@eregon eregon changed the title The gem is broken on truffleruby and jruby The fiddle gem is broken on truffleruby and jruby Sep 16, 2024
kou added a commit that referenced this issue Sep 29, 2024
Fix GH-145

lib/fiddle/truffleruby.rb is based on
https://github.com/oracle/truffleruby/blob/master/lib/truffle/truffle/fiddle_backend.rb
.

Here are changes for it:

* Add `Fiddle::Types::VARIADIC`
* Add `Fiddle::Types::CONST_STRING`
* Add `Fiddle::Types::BOOL`
* Add `Fiddle::ALIGN_BOOL`
* Add `Fiddle::SIZEOF_BOOL`
* Add `Fiddle::SIZEOF_CONST_STRING`
* Add support for specifying type as not only `Fiddle::Types::*` but also
  `Symbol` like `:int`
* Add `Fiddle::Error` as base the error class
* Add support for `Fiddle::Pointer.malloc {}`
  `Fiddle::Pointer`
* Add support for `Fiddle.free(#to_int)`
* Accept `Fiddle::Function(need_gvl:)` but it's just ignored
* `Fiddle::Function#initialize`: Add an argument validation
* `Fiddle::Function#initialize`: Keep arguments as instance variables for
  getters
* Add support for `Fiddle::Handle.sym`
* Add support for `Fiddle::Handle.[]`
* Add support for `Fiddle::Handle.sym_defined?`
* Add support for `Fiddle::Handle#sym`
* Add support for `Fiddle::Handle#[]`
* Add support for `Fiddle::Handle#sym_defined?`
* Add support for `Fiddle::Pointer.malloc`
* Add support for `Fiddle::Pointer.to_ptr(#to_ptr)`
* Add support for `Fiddle::Pointer#free=`
* Add `Fiddle::Pointer#freed?`
* Add support for `Fiddle::Pointer#call_free`
* Add support for `Fiddle::Pointer#to_i`
* Add support for `Fiddle::Pointer#to_int`
* Add support for `Fiddle::Pointer#ptr`
* Add support for `Fiddle::Pointer#+@`
* Add support for `Fiddle::Pointer#ref`
* Add support for `Fiddle::Pointer#-@`
* Add support for `Fiddle::Pointer#null?`
* Add support for `Fiddle::Pointer#to_s`
* Add support for `Fiddle::Pointer#to_str`
* Add support for `Fiddle::Pointer#inspect`
* Add support for `Fiddle::Pointer#<=>`
* Add support for `Fiddle::Pointer#==`
* Add support for `Fiddle::Pointer#eql?`
* Add support for `Fiddle::Pointer#+`
* Add support for `Fiddle::Pointer#-`
* Add support for `Fiddle::Pointer#[]=`
* Add support for `Fiddle::Pointer#size`
* Add support for `Fiddle::Pointer#size=`
* Add `Fiddle::ClearedReferenceError`
* Add no-op `Fiddle::Pinned`
* Add `Fiddle::NULL`

Some features are still "not implemented". So there are some "omit"s
for TruffleRuby in tests.
kou added a commit that referenced this issue Oct 7, 2024
Fix GH-145

lib/fiddle/truffleruby.rb uses lib/fiddle/jruby.rb.
lib/fiddle/jruby.rb uses FFI API. So we can use it for TruffleRuby
too.
kou added a commit that referenced this issue Oct 7, 2024
Fix GH-145

lib/fiddle/truffleruby.rb uses lib/fiddle/jruby.rb.
lib/fiddle/jruby.rb uses FFI API. So we can use it for TruffleRuby
too.
eregon pushed a commit that referenced this issue Oct 8, 2024
Fix GH-145

lib/fiddle/truffleruby.rb is based on
https://github.com/oracle/truffleruby/blob/master/lib/truffle/truffle/fiddle_backend.rb
.

Here are changes for it:

* Add `Fiddle::Types::VARIADIC`
* Add `Fiddle::Types::CONST_STRING`
* Add `Fiddle::Types::BOOL`
* Add `Fiddle::ALIGN_BOOL`
* Add `Fiddle::SIZEOF_BOOL`
* Add `Fiddle::SIZEOF_CONST_STRING`
* Add support for specifying type as not only `Fiddle::Types::*` but also
  `Symbol` like `:int`
* Add `Fiddle::Error` as base the error class
* Add support for `Fiddle::Pointer.malloc {}`
  `Fiddle::Pointer`
* Add support for `Fiddle.free(#to_int)`
* Accept `Fiddle::Function(need_gvl:)` but it's just ignored
* `Fiddle::Function#initialize`: Add an argument validation
* `Fiddle::Function#initialize`: Keep arguments as instance variables for
  getters
* Add support for `Fiddle::Handle.sym`
* Add support for `Fiddle::Handle.[]`
* Add support for `Fiddle::Handle.sym_defined?`
* Add support for `Fiddle::Handle#sym`
* Add support for `Fiddle::Handle#[]`
* Add support for `Fiddle::Handle#sym_defined?`
* Add support for `Fiddle::Pointer.malloc`
* Add support for `Fiddle::Pointer.to_ptr(#to_ptr)`
* Add support for `Fiddle::Pointer#free=`
* Add `Fiddle::Pointer#freed?`
* Add support for `Fiddle::Pointer#call_free`
* Add support for `Fiddle::Pointer#to_i`
* Add support for `Fiddle::Pointer#to_int`
* Add support for `Fiddle::Pointer#ptr`
* Add support for `Fiddle::Pointer#+@`
* Add support for `Fiddle::Pointer#ref`
* Add support for `Fiddle::Pointer#-@`
* Add support for `Fiddle::Pointer#null?`
* Add support for `Fiddle::Pointer#to_s`
* Add support for `Fiddle::Pointer#to_str`
* Add support for `Fiddle::Pointer#inspect`
* Add support for `Fiddle::Pointer#<=>`
* Add support for `Fiddle::Pointer#==`
* Add support for `Fiddle::Pointer#eql?`
* Add support for `Fiddle::Pointer#+`
* Add support for `Fiddle::Pointer#-`
* Add support for `Fiddle::Pointer#[]=`
* Add support for `Fiddle::Pointer#size`
* Add support for `Fiddle::Pointer#size=`
* Add `Fiddle::ClearedReferenceError`
* Add no-op `Fiddle::Pinned`
* Add `Fiddle::NULL`

Some features are still "not implemented". So there are some "omit"s
for TruffleRuby in tests.
kou added a commit that referenced this issue Oct 10, 2024
Fix GH-145

Rename `lib/fiddle/jruby.rb` to `lib/fiddle/ffi_backend.rb` as a generic
ffi gem API based implementation.
JRuby and TruffleRuby use `lib/fiddle/ffi_backend.rb`.

---------

Co-authored-by: Benoit Daloze <[email protected]>
@kou kou closed this as completed in #149 Oct 10, 2024
@eregon
Copy link
Member Author

eregon commented Oct 10, 2024

@kou Thank you for your help fixing this.
Could you make a fiddle release?
Then there should be no problem when gems/Gemfile's depend on fiddle for JRuby & TruffleRuby.

@kou
Copy link
Member

kou commented Oct 11, 2024

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants