Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Accept non-UnwindSafe extern Rust types in extern Rust signatures #91

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/unwind.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::io::{self, Write};
use std::panic::{self, UnwindSafe};
use std::panic::{self, AssertUnwindSafe};
use std::process;

pub fn catch_unwind<F, R>(label: &'static str, foreign_call: F) -> R
where
F: FnOnce() -> R + UnwindSafe,
F: FnOnce() -> R,
{
match panic::catch_unwind(foreign_call) {
// Regarding the AssertUnwindSafe: we immediately abort on panic so it
// doesn't matter whether the types involved are unwind-safe. The UnwindSafe
// bound on catch_unwind is about ensuring nothing is in a broken state if
// your program plans to continue after the panic.
match panic::catch_unwind(AssertUnwindSafe(foreign_call)) {
Ok(ret) => ret,
Err(_) => abort(label),
}
Expand Down