Skip to content

RString needs to be panic safe std::panic::catch_unwind #73

@danielpclark

Description

@danielpclark

Ruby has this particular string in it's own test suite:

filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8

https://github.com/ruby/ruby/blob/b67ead14521fb74bcf8ec28f8c78245dfb536b70/test/ruby/test_dir_m17n.rb#L72

This will cause ruru to panic:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err`
value: Utf8Error { valid_up_to: 0, error_len: Some(1) }', /checkout/src/libcore/result.rs:906:4

I've tried wrapping it in a thread but that failed.

In Rust, panic is safe and per-thread. The boundaries between threads serve as a firewall for panic;

  • Programming Rust by Jim Blandy, Jason Orendorff

I then found Rust's std::panic::catch_unwind which according to the original RFC is meant to handle such panics from C method calls. The catch_unwind doc has this note:

Note that this function may not catch all panics in Rust. A panic in Rust is not always implemented via unwinding, but can be implemented by aborting the process as well. This function only catches unwinding panics, not those that abort the process.

I have thus far been unable to catch the panic from this and looking up the error Utf8Error it would seem that that is a side effect of the kind of methods used from libruby for RString and that error isn't written in ruru.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions