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

Cannot load more than one byte from RSTRING_PTR #1772

Closed
XrXr opened this issue Oct 22, 2019 · 3 comments
Closed

Cannot load more than one byte from RSTRING_PTR #1772

XrXr opened this issue Oct 22, 2019 · 3 comments

Comments

@XrXr
Copy link
Contributor

XrXr commented Oct 22, 2019

I'm trying to run google-protobuf on TruffleRuby. The gem contains a C extension that computes a hash code off of Ruby strings, and TruffleRuby does not execute the hash function correctly.

I have reduced the code down to a simple demo extension here that you can play with: https://gist.github.com/XrXr/d7a07623330c244cb3b13bcae5f9530e.
As you can see in the output, TruffleRuby reads out a single byte instead of the expected four.
The hash function in protobuf is here: https://github.com/protocolbuffers/protobuf/blob/c08b7512cf9d65899e8e84edd02d4335a64b11b0/ruby/ext/google/protobuf_c/upb.c#L2007

Digging into the code RSTRING_PTR returns a polyglot object, which only supports single byte loads:

Truffle::CExt.string_pointer_read(@string, index)

return getByteNode.executeGetByte(rope, index);

Related, Sulong computes the index into the polyglot object in an undesirable way:
https://github.com/oracle/graal/blob/cbee70bd6f3e0c487e1340ace299eb3813596922/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/access/LLVMInteropReadNode.java#L72
The division makes it so that the byte being read out in a multiple-byte load isn't necessarily the byte at that address.

@eregon
Copy link
Member

eregon commented Oct 23, 2019

Thank you for this excellent bug report and investigation.

I guess we need to tell Sulong that our RStringPtr object needs to be addressed byte-wise.

@eregon eregon self-assigned this Oct 23, 2019
@eregon
Copy link
Member

eregon commented Nov 8, 2019

Filed as a Sulong bug internally as GR-19473.

@eregon
Copy link
Member

eregon commented Jan 30, 2020

This is fixed with 9a22abd and 1bf2f6a, by always returning a native pointer for RSTRING_PTR. It will be in the 20.0 release. Thank you for the bug report!

@eregon eregon closed this as completed Jan 30, 2020
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