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

Incorrect address for unsigned integers with ffi #1315

Closed
djberg96 opened this issue Dec 7, 2013 · 7 comments
Closed

Incorrect address for unsigned integers with ffi #1315

djberg96 opened this issue Dec 7, 2013 · 7 comments

Comments

@djberg96
Copy link
Contributor

djberg96 commented Dec 7, 2013

It seems that when using JRuby and ffi it returns an incorrect value for the address of an unsigned integer:

# Should be (1 << FFI::Platform::ADDRESS_SIZE) - 1
FFI::Pointer.new(-1).address # Returns -1 instead of correct value

This came up when trying to define INVALID_HANDLE_VALUE on Windows which internally is defined using a cast:

// 0xFFFFFFFF on 32 bit systems, 0xFFFFFFFFFFFFFFFF on 64 bit systems
INVALID_HANDLE_VALUE = (DWORD)-1;

I realize JRuby isn't big on addresses in general, but here I think we can simulate casting a negative int here to match C's behavior.

Originally reported on the ffi project, but was told to report it here.

@larskanis
Copy link

For reference the issue on ffi gem: ffi/ffi#313

@tduehr
Copy link
Contributor

tduehr commented Feb 5, 2015

This is solved by:

address && Platform.getPlatform().addressMask()

The only question is where do we perform that? at initialization? on #address? both?
@enebo @headius comments?

@djberg96
Copy link
Contributor Author

djberg96 commented Feb 5, 2016

Still happening as of 9.0.5.0.

@tduehr
Copy link
Contributor

tduehr commented Feb 5, 2016

I'm not sure this can be fixed on 64bit systems. Since Java doesn't have unsigned integer types, I think we'd have to change the API to return a BigInteger to get 0xFFFFFFFFFFFFFFFF as a positive value.

@djberg96
Copy link
Contributor Author

@tduehr Any update?

@djberg96
Copy link
Contributor Author

@enebo @headius @tduehr Still happening as of 9.1.12.

@djberg96
Copy link
Contributor Author

Looks like it's dead, just cleaning up my queue.

@enebo enebo added this to the Invalid or Duplicate milestone Apr 19, 2018
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

No branches or pull requests

4 participants