Expand unsafety on extern C++ functions
diff --git a/macro/src/expand.rs b/macro/src/expand.rs
index 2f797b0..879431e 100644
--- a/macro/src/expand.rs
+++ b/macro/src/expand.rs
@@ -399,17 +399,19 @@
})
}
.unwrap_or(call);
+ let mut dispatch = quote!(#setup #expr);
+ let unsafety = &efn.sig.unsafety;
+ if unsafety.is_none() {
+ dispatch = quote!(unsafe { #dispatch });
+ }
let function_shim = quote! {
#doc
- pub fn #ident(#(#all_args,)*) #ret {
+ pub #unsafety fn #ident(#(#all_args,)*) #ret {
extern "C" {
#decl
}
#trampolines
- unsafe {
- #setup
- #expr
- }
+ #dispatch
}
};
match &efn.receiver {