summaryrefslogtreecommitdiff
path: root/bindgen/codegen/dyngen.rs
diff options
context:
space:
mode:
authorChristian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com>2022-11-04 15:22:49 -0500
committerGitHub <noreply@github.com>2022-11-04 15:22:49 -0500
commite8ffb42ab66405ac56d04494a30e54b584f2d4dd (patch)
tree35076ed9ef6b63542a62c2ea3ecf7aac0b314d30 /bindgen/codegen/dyngen.rs
parentbae6170907dd27a1e854236e2cc7b4f637220977 (diff)
Wrap `unsafe` function's bodies in `unsafe` blocks (#2266)
This guarantees that bindings generated by `bindgen` compile even if the `unsafe_op_in_unsafe_fn` lint is denied.
Diffstat (limited to 'bindgen/codegen/dyngen.rs')
-rw-r--r--bindgen/codegen/dyngen.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs
index d02c51e4..f310f14e 100644
--- a/bindgen/codegen/dyngen.rs
+++ b/bindgen/codegen/dyngen.rs
@@ -92,7 +92,9 @@ impl DynamicItems {
) -> Result<Self, ::libloading::Error>
where P: AsRef<::std::ffi::OsStr> {
let library = ::libloading::Library::new(path)?;
- Self::from_library(library)
+ unsafe {
+ Self::from_library(library)
+ }
}
pub unsafe fn from_library<L>(
@@ -157,7 +159,9 @@ impl DynamicItems {
self.struct_implementation.push(quote! {
#(#attributes)*
pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty {
- #call_body
+ unsafe {
+ #call_body
+ }
}
});
}
@@ -166,11 +170,11 @@ impl DynamicItems {
let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string());
self.constructor_inits.push(if is_required {
quote! {
- let #ident = __library.get(#ident_str).map(|sym| *sym)?;
+ let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym)?;
}
} else {
quote! {
- let #ident = __library.get(#ident_str).map(|sym| *sym);
+ let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym);
}
});