Skip to content

Commit 594009b

Browse files
WardBrianpvdrz
authored andcommitted
Wrap libloading::Library::new call in unsafe if --wrap-unsafe-ops
1 parent 8a6d851 commit 594009b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen/codegen/dyngen.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ impl DynamicItems {
8383
let init_fields = &self.init_fields;
8484
let struct_implementation = &self.struct_implementation;
8585

86+
let library_new = if ctx.options().wrap_unsafe_ops {
87+
quote!(unsafe { ::libloading::Library::new(path) })
88+
} else {
89+
quote!(::libloading::Library::new(path))
90+
};
91+
8692
let from_library = if ctx.options().wrap_unsafe_ops {
8793
quote!(unsafe { Self::from_library(library) })
8894
} else {
@@ -100,7 +106,7 @@ impl DynamicItems {
100106
path: P
101107
) -> Result<Self, ::libloading::Error>
102108
where P: AsRef<::std::ffi::OsStr> {
103-
let library = ::libloading::Library::new(path)?;
109+
let library = #library_new?;
104110
#from_library
105111
}
106112

0 commit comments

Comments
 (0)