-
Notifications
You must be signed in to change notification settings - Fork 776
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
Panics should be caught at the FFI boundary and propagated into python some other way #492
Comments
I'm going to have a go at this in the next week or so - seems like a relatively self-contained change with big payoff for safety. |
Related: rust-lang/rfcs#2797 |
I don't think so, just because we have too many |
Agreed - what I meant is that only the |
What I'm leaning towards is adding a new utility function I'm still iterating on the exact design of |
Sound nice 👍 , though I think it's also good to use |
Hmm but I noticed we can't retrieve panic information from catch_unwind. |
It is true that We could maybe do something nice with |
Ah, I understand, thanks. |
|
Yes, that's how I'm currently playing with formatting panic messages. |
All Rust stack frames which have FFI stack frames directly under them should be guarded by a
catch_unwind
to ensure that it is impossible to accidentally panic back into Python’s stack frames. It is undefined behaviour to panic-unwind into stack frames of functions written in other languages, which makes any Rust-written python method that may panic for any reason – pyo3 is not exempt – unsound.Alternatively, users of
pyo3
should be instructed to wrap their code intocatch_unwind
and handle this scenario on their own. In that case the requirement to not panic withoutcatch_unwind
should be thoroughly documented.For reference, I encountered this issue by experimenting with errors and doing something along the lines of:
Where
PyErr
panicked becauseException
is not a validException
type.The text was updated successfully, but these errors were encountered: