-
Notifications
You must be signed in to change notification settings - Fork 29
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
FasterPath.blank? panics if string has invalid encoding #67
Comments
Thanks for this. I believe we need to implement a way to raise Ruby exceptions directly from Rust. I am concerned about the performance hit wrapping the response in an Ok, Err thing and the implementation detail of Ruby expecting something specific back with FFI. |
I have no experience with this, but you can have the rust code return:
And have a small |
Rust requires a specific type returned for any method. If you need more then one type you build a higher type which will encapsulate the kinds of things you want to return. But by doing this very thing you lose efficiency in packaging an unpacking the types. Using There are other ways |
I've noticed that |
@dubek Looking at Ruby's FFI spec custom_type_spec.rb it appears we can implement the proper returns like you've outlined. |
Can we not call rb_raise directly from rust code? |
Rust allows only 1 type to be returned and FFI even more so expects one type to be returned. To model multiple types we have to create our own type, which will wrap both types, which we can do in both Rust and FFI with Structs. But then thinking about how to handle the struct in Ruby we might be adding something like raise struct.error if struct.error otherwise return struct.value . That Ruby conditional will likely cost us lots in performance I'm not sure how deeply coupled the FFI lib is within the code that is written in itself. For example we can do callbacks which lets us evaluate a block in another call to "Rust" but still has the original method returning a type... which should be of one type of return. I think the issue really comes down to how much we can cheat the one return type design and how much FFI will let us conditionally return that value without higher level Ruby code evaluating that condition. |
Found this in Ruby's own test suite filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8 I'd like to try it on the parameter handed to Rust and see if it does anything. |
Now that this code base has been rewritten to ruru the issue lies in the implementation of RString: d-unsed/ruru#73 |
This information is useful still for any inputs for Rust implemented methods. I'm closing this issue because I've removed the Rust implementation of |
To reproduce the crash:
The issue is the
unwrap()
call insrc/is_blank.rs
.The expected behaviour is that it'll raise an ArgumentError exception ("invalid byte sequence in UTF-8"), like Ruby's String#match in
"\xff".match(/ /)
The text was updated successfully, but these errors were encountered: