Skip to content

Use JRuby implementation for TruffleRuby - #149

Merged
kou merged 6 commits into
masterfrom
truffleruby-ffi
Oct 10, 2024
Merged

Use JRuby implementation for TruffleRuby#149
kou merged 6 commits into
masterfrom
truffleruby-ffi

Conversation

@kou

@koukou commented Oct 7, 2024

Copy link
Copy Markdown
Member

FixGH-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.

FixGH-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.

@eregoneregon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, I'd like to investigate a couple things.

Comment threadlib/fiddle/jruby.rb
Comment threadtest/fiddle/test_closure.rb Outdated
class TestClosure < Fiddle::TestCase
def setup
if RUBY_ENGINE == "truffleruby"
omit("FFI::Function don't accept #call-able object with TruffleRuby")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this, TruffleRuby does pass most FFI gem tests so it's surprising, maybe this is not well tested or is not an officially supported API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 41c21f5 so all such tests pass now

Comment threadlib/fiddle/jruby.rb
@@ -158,6 +158,17 @@ def call(*args, &block);
end

@eregoneregonOct 7, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to rename this file to ffi_backend.rb or so and avoid a JRuby namespace since it is effectively independent from JRuby but it doesn't like that currently due to file naming and things like Fiddle::JRuby.
It's helpful to have a small diff at this point though, so I think that's best done later, maybe even in a separate PR.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we don't need to do it because this is a short-term workaround for TruffleRuby.
This file will be used by only JRuby eventually.

@eregoneregonOct 8, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the FFI backend seems to work well I think we should just use it long term, for both JRuby and TruffleRuby.
It's also nice to have 2 backends instead of 3.

* The issue is Fiddle structs have #to_ptr returning a CStructEntity and
not a FFI::Pointer.
So both Fiddle and FFI use #to_ptr and we need explicit coercion.
* TruffleRuby requires a Proc or Method as the callable.
assert_equal("1349", buff, bug4929)

# Ensure the test didn't mutate String literals
assert_equal("93" + "41", untouched)

@eregoneregonOct 8, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the added + above this was failing, which meant Fiddle tests were permanently changing the meaning of all "9341" frozen string literals.

Interestingly this sanity check actually fails on JRuby, I'll file an issue there: jruby/jruby#8365

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JRuby issue has been fixed on master and will be in JRuby 9.4.9.0.

We won't be updating 9.4 to use the fiddle gem in any case, but the test could be un-omitted now.

@eregoneregon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready, I am happy with this solution.

Comment threadlib/fiddle/truffleruby.rb Outdated
@kou
kou merged commit f6d313a into masterOct 10, 2024
@kou
kou deleted the truffleruby-ffi branch October 10, 2024 05:37
@koukou mentioned this pull request Oct 10, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The fiddle gem is broken on truffleruby and jruby

4 participants

@kou@headius@eregon@Maumagnaguagno