I wanted to reproduce this behavior, but instead of abort
got an unwind
. Note that I haven't compiled it with "panic=abort".
Static lib code:
#[no_mangle]
pub extern "C" fn do_panic() {
println!("Inner panic");
panic!()
}
Caller code:
use std::panic::catch_unwind;
fn main() {
catch_unwind(|| {
println!("Entering catch");
unsafe { do_panic() }
})
.expect_err("Caught!");
println!("I'm still here");
}
extern "C" {
fn do_panic();
}
The output:
Entering catch
Inner panic
thread 'main' panicked at 'explicit panic', src/lib.rs:4:5
stack backtrace:
0: rust_begin_unwind
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
2: core::panicking::panic
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5
3: do_panic
4: handle_ffi_panic::main::{{closure}}
at ./src/main.rs:6:18
5: std::panicking::try::do_call
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
6: __rust_try
7: std::panicking::try
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
8: std::panic::catch_unwind
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
9: handle_ffi_panic::main
at ./src/main.rs:4:5
10: core::ops::function::FnOnce::call_once
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
I'm still here
-
I guess nomicon info is outdated? Did I misunderstand something? This also works if I encapsulate panicking lib call inside C-lib call
-
Should that be the case only when it is
extern "C-unwind"
?