You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recover function is able, on a single thread, to recover from a panic. There are numerous controversies around this API, including the bounds it applies to its closure, its safety, and its location within std. An open RFC seeks to settle these issues and open the door to stabilization.
I’m playing with making Python bindings for a Rust library, and I got some segfaults when a Rust panic tried to unwind into the Python interpreter’s call stack. I understand that using catch_panic at the FFI boundary is the right thing to do, but what should I do with an Err result? I can establish conventions so that the other side triggers a Python exception, but I’d like to have some more helpful information in it than "Something bad happened somewhere". At least (a string representation of) the message that was given to panic!, ideally also a back trace of the unwinded stack frames.
catch_panic returns Result<T, Box<Any + Send + 'static>>, but Any is not very helpful here. It implements Debug, but that impl only prints "Any" (literally), which isn’t that helpful.
@wycats, how do you deal with panics in Rust-inside-Ruby?
@SimonSapin Looking at the guts of unwinding, Box<Any + Send + 'static> is always going to either be String (if panic!() had formatting arguments) or &'static str (if panic!() was invoked with just a string literal), so you basically downcast it to one, and if that fails you can probably assume it's the other.
I agree, though, the type could be a lot more informative here.
Why not have impl Debug for Any (+ Send) test for the value being String or &'static str before printing "Any"? It would add negligible overhead, and I don't think anyone should be relying on the exact value it prints. Right now, it's pretty much useless anyways.
In fact, why not cover all the primitives (except obviously &[T], *const T, *mut T, etc)?
I thought the barrier suggestion from @cybergeek94 was good. Especially if we put it into an unwind submodule, yielding unwind::barrier
To me barrier carries the notion that the unwinding will stop here, but there's the hint that you should perhaps trying to "restart it", to keep it going across the boundary introduced by the barrier, if possible, or at least signal that it occurred.
Update: unwind::guard seems okay too, but for some reason I prefer unwind::barrier; not sure why.
My vote against "barrier", sounds too non-related to execution flow.
On Wed, 6 Apr 2016 at 22:32, Felix S Klock II [email protected]
wrote:
I thought the barrier suggestion from @cybergeek94 https://github.com/cybergeek94 was good. Especially if we put it into
an unwind submodule, yielding unwind::barrier
To me barrier carries the notion that the unwinding will stop here, but
there's the hint that you should perhaps trying to "restart it", to keep it
going across the boundary introduced by the barrier, if possible, or at
least signal that it occurred.
—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub #27719 (comment)
Activity
SimonSapin commentedon Sep 16, 2015
I’m playing with making Python bindings for a Rust library, and I got some segfaults when a Rust panic tried to unwind into the Python interpreter’s call stack. I understand that using
catch_panicat the FFI boundary is the right thing to do, but what should I do with anErrresult? I can establish conventions so that the other side triggers a Python exception, but I’d like to have some more helpful information in it than "Something bad happened somewhere". At least (a string representation of) the message that was given topanic!, ideally also a back trace of the unwinded stack frames.catch_panicreturnsResult<T, Box<Any + Send + 'static>>, butAnyis not very helpful here. It implementsDebug, but that impl only prints"Any"(literally), which isn’t that helpful.@wycats, how do you deal with panics in Rust-inside-Ruby?
abonander commentedon Oct 3, 2015
@SimonSapin Looking at the guts of unwinding,
Box<Any + Send + 'static>is always going to either beString(ifpanic!()had formatting arguments) or&'static str(ifpanic!()was invoked with just a string literal), so you basically downcast it to one, and if that fails you can probably assume it's the other.I agree, though, the type could be a lot more informative here.
SimonSapin commentedon Oct 3, 2015
Yeah, I ended up finding this code: https://github.com/rust-lang/rust/blob/d2047bc97d/src/libstd/panicking.rs#L33-L39 , but it’s not very discoverable. And though
Stringand&'static strare the most common cases,panic!()with a single argument can take any type:So I wanted to propose changing from this (in
std::thread):to this:
… but
std::thread::Resultis already stable :(SimonSapin commentedon Oct 3, 2015
Would this
as_strbelong as a default method on theAnytrait?abonander commentedon Oct 3, 2015
Why not have
impl Debug for Any (+ Send)test for the value beingStringor&'static strbefore printing"Any"? It would add negligible overhead, and I don't think anyone should be relying on the exact value it prints. Right now, it's pretty much useless anyways.In fact, why not cover all the primitives (except obviously
&[T],*const T,*mut T, etc)?alexchandel commentedon Dec 2, 2015
Why are we making it easier to use and abuse panics, instead of removing inappropriate ones from the standard library?
106 remaining items
BurntSushi commentedon Apr 6, 2016
I think I'm happy as long as
unwindis in the name.pnkfelix commentedon Apr 6, 2016
I thought the
barriersuggestion from @cybergeek94 was good. Especially if we put it into anunwindsubmodule, yieldingunwind::barrierTo me
barriercarries the notion that the unwinding will stop here, but there's the hint that you should perhaps trying to "restart it", to keep it going across the boundary introduced by thebarrier, if possible, or at least signal that it occurred.Update:
unwind::guardseems okay too, but for some reason I preferunwind::barrier; not sure why.e-oz commentedon Apr 6, 2016
My vote against "barrier", sounds too non-related to execution flow.
On Wed, 6 Apr 2016 at 22:32, Felix S Klock II [email protected]
wrote:
tomaka commentedon Apr 6, 2016
In system programming,
barrierusually means "memory barrier", which has nothing to do with unwinding.alexcrichton commentedon Apr 7, 2016
The libs team discussed this during triage yesterday and the decision was to stabilize with the following names:
recover->catch_unwindpropagate->resume_unwindAssertRecoverSafe->AssertUnwindSafeThanks again for all the discussion everyone!
strega-nil commentedon Apr 7, 2016
yay :)
std: Stabilize APIs for the 1.9 release
Auto merge of #32804 - alexcrichton:stabilize-1.9, r=brson
std: Stabilize APIs for the 1.9 release