From 4ad8020fc4eec61e4cfb2b6efb75333ba1dbdf17 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 8 Apr 2020 21:16:44 -0700 Subject: [PATCH] Accept non-UnwindSafe extern Rust types in extern Rust signatures --- src/unwind.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/unwind.rs b/src/unwind.rs index 070aa28fe..abb7b921a 100644 --- a/src/unwind.rs +++ b/src/unwind.rs @@ -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(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), }