Skip to content

Commit

Permalink
Expand unsafety on extern C++ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 7, 2020
1 parent bdb576c commit e67bcf5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions macro/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,19 @@ fn expand_cxx_function_shim(namespace: &Namespace, efn: &ExternFn, types: &Types
})
}
.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 {
Expand Down

0 comments on commit e67bcf5

Please sign in to comment.