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

Allow ulong range values to coerce to long bits #6406

Merged
merged 1 commit into from
Sep 22, 2020

Conversation

headius
Copy link
Member

@headius headius commented Sep 21, 2020

This adds ulong versions of the numeric-to-long conversion methods
that allow ulong-ranged values to be coerced to a Java long.
Callers must take care to use the resulting long correctly, since
Java will always see it as signed.

Added primarily to support ulong use cases in FFI, and fixes #6376
and a test commented out due to jnr/jffi#87.

The tests in question can be enabled via the following patch:

diff --git a/spec/ffi/struct_spec.rb b/spec/ffi/struct_spec.rb
index 70e60c15a9..b5e262a04a 100644
--- a/spec/ffi/struct_spec.rb
+++ b/spec/ffi/struct_spec.rb
@@ -365,17 +365,17 @@ module StructSpecsStructTests
     int_field_test(:int, [ 0, 0x7fffffff, -0x80000000, -1 ])
     int_field_test(:uint, [ 0, 0x7fffffff, 0x80000000, 0xffffffff ])
     int_field_test(:long_long, [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ])
-    if RUBY_ENGINE != 'jruby' # https://github.com/jnr/jffi/issues/87
+    # if RUBY_ENGINE != 'jruby' # https://github.com/jnr/jffi/issues/87
       int_field_test(:ulong_long, [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ])
-    end
+    # end
     if FFI::Platform::LONG_SIZE == 32
       int_field_test(:long, [ 0, 0x7fffffff, -0x80000000, -1 ])
       int_field_test(:ulong, [ 0, 0x7fffffff, 0x80000000, 0xffffffff ])
     else
       int_field_test(:long, [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ])
-      if RUBY_ENGINE != 'jruby' # https://github.com/jruby/jruby/issues/6376
+      # if RUBY_ENGINE != 'jruby' # https://github.com/jruby/jruby/issues/6376
         int_field_test(:ulong, [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ])
-      end
+      # end
     end
 
     it ":float field r/w" do

This adds ulong versions of the numeric-to-long conversion methods
that allow ulong-ranged values to be coerced to a Java long.
Callers must take care to use the resulting long correctly, since
Java will always see it as signed.

Added primarily to support ulong use cases in FFI, and fixes jruby#6376
and a test commented out due to jnr/jffi#87.
@ahorek
Copy link
Contributor

ahorek commented Sep 22, 2020

thanks for looking into this! 👍

@ahorek ahorek self-requested a review September 22, 2020 14:41
@headius headius merged commit 21eb13d into jruby:master Sep 22, 2020
@headius headius deleted the fix_struct_ulong branch September 22, 2020 17:27
Sign up for free to 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.

[ffi] ulong type looses precision in 64bit mode
2 participants