summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDr. Chat <arkolbed@gmail.com>2021-03-26 17:12:23 -0500
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-04-03 12:24:15 +0200
commit2c5a1ea6b1bd56085d726dac347a31c49c95be76 (patch)
treea15de55e4d75073c218877d105fb478d83f6bc15 /tests
parente0157a648f87c4f86fe1a1e6d5bd0502b5eb265a (diff)
Add a flag to ensure all symbols are resolved when a library is loaded
Diffstat (limited to 'tests')
-rw-r--r--tests/expectations/tests/dynamic_loading_required.rs59
-rw-r--r--tests/expectations/tests/dynamic_loading_simple.rs8
-rw-r--r--tests/expectations/tests/dynamic_loading_template.rs8
-rw-r--r--tests/expectations/tests/dynamic_loading_with_allowlist.rs8
-rw-r--r--tests/expectations/tests/dynamic_loading_with_blocklist.rs8
-rw-r--r--tests/expectations/tests/dynamic_loading_with_class.rs8
-rw-r--r--tests/headers/dynamic_loading_required.h5
7 files changed, 84 insertions, 20 deletions
diff --git a/tests/expectations/tests/dynamic_loading_required.rs b/tests/expectations/tests/dynamic_loading_required.rs
new file mode 100644
index 00000000..3600eace
--- /dev/null
+++ b/tests/expectations/tests/dynamic_loading_required.rs
@@ -0,0 +1,59 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+extern crate libloading;
+pub struct TestLib {
+ __library: ::libloading::Library,
+ pub foo: unsafe extern "C" fn(
+ x: ::std::os::raw::c_int,
+ y: ::std::os::raw::c_int,
+ ) -> ::std::os::raw::c_int,
+ pub bar: unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ pub baz: unsafe extern "C" fn() -> ::std::os::raw::c_int,
+}
+impl TestLib {
+ pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
+ where
+ P: AsRef<::std::ffi::OsStr>,
+ {
+ let library = ::libloading::Library::new(path)?;
+ Self::from_library(library)
+ }
+ pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
+ where
+ L: Into<::libloading::Library>,
+ {
+ let __library = library.into();
+ let foo = __library.get(b"foo\0").map(|sym| *sym)?;
+ let bar = __library.get(b"bar\0").map(|sym| *sym)?;
+ let baz = __library.get(b"baz\0").map(|sym| *sym)?;
+ Ok(TestLib {
+ __library,
+ foo,
+ bar,
+ baz,
+ })
+ }
+ pub unsafe fn foo(
+ &self,
+ x: ::std::os::raw::c_int,
+ y: ::std::os::raw::c_int,
+ ) -> ::std::os::raw::c_int {
+ self.foo(x, y)
+ }
+ pub unsafe fn bar(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ self.bar(x)
+ }
+ pub unsafe fn baz(&self) -> ::std::os::raw::c_int {
+ self.baz()
+ }
+}
diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs
index c9c4ba15..3d2e3d2c 100644
--- a/tests/expectations/tests/dynamic_loading_simple.rs
+++ b/tests/expectations/tests/dynamic_loading_simple.rs
@@ -32,9 +32,9 @@ impl TestLib {
P: AsRef<::std::ffi::OsStr>,
{
let library = ::libloading::Library::new(path)?;
- Ok(Self::from_library(library))
+ Self::from_library(library)
}
- pub unsafe fn from_library<L>(library: L) -> Self
+ pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
where
L: Into<::libloading::Library>,
{
@@ -42,12 +42,12 @@ impl TestLib {
let foo = __library.get(b"foo\0").map(|sym| *sym);
let bar = __library.get(b"bar\0").map(|sym| *sym);
let baz = __library.get(b"baz\0").map(|sym| *sym);
- TestLib {
+ Ok(TestLib {
__library,
foo,
bar,
baz,
- }
+ })
}
pub unsafe fn foo(
&self,
diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs
index a46253c6..de231434 100644
--- a/tests/expectations/tests/dynamic_loading_template.rs
+++ b/tests/expectations/tests/dynamic_loading_template.rs
@@ -20,20 +20,20 @@ impl TestLib {
P: AsRef<::std::ffi::OsStr>,
{
let library = ::libloading::Library::new(path)?;
- Ok(Self::from_library(library))
+ Self::from_library(library)
}
- pub unsafe fn from_library<L>(library: L) -> Self
+ pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
where
L: Into<::libloading::Library>,
{
let __library = library.into();
let foo = __library.get(b"foo\0").map(|sym| *sym);
let foo1 = __library.get(b"foo1\0").map(|sym| *sym);
- TestLib {
+ Ok(TestLib {
__library,
foo,
foo1,
- }
+ })
}
pub unsafe fn foo(
&self,
diff --git a/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/tests/expectations/tests/dynamic_loading_with_allowlist.rs
index 678cd340..83e4a541 100644
--- a/tests/expectations/tests/dynamic_loading_with_allowlist.rs
+++ b/tests/expectations/tests/dynamic_loading_with_allowlist.rs
@@ -34,9 +34,9 @@ impl TestLib {
P: AsRef<::std::ffi::OsStr>,
{
let library = ::libloading::Library::new(path)?;
- Ok(Self::from_library(library))
+ Self::from_library(library)
}
- pub unsafe fn from_library<L>(library: L) -> Self
+ pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
where
L: Into<::libloading::Library>,
{
@@ -44,12 +44,12 @@ impl TestLib {
let foo = __library.get(b"foo\0").map(|sym| *sym);
let baz = __library.get(b"baz\0").map(|sym| *sym);
let bazz = __library.get(b"bazz\0").map(|sym| *sym);
- TestLib {
+ Ok(TestLib {
__library,
foo,
baz,
bazz,
- }
+ })
}
pub unsafe fn foo(
&self,
diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs
index 930876a4..598780b2 100644
--- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs
+++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs
@@ -78,20 +78,20 @@ impl TestLib {
P: AsRef<::std::ffi::OsStr>,
{
let library = ::libloading::Library::new(path)?;
- Ok(Self::from_library(library))
+ Self::from_library(library)
}
- pub unsafe fn from_library<L>(library: L) -> Self
+ pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
where
L: Into<::libloading::Library>,
{
let __library = library.into();
let foo = __library.get(b"foo\0").map(|sym| *sym);
let bar = __library.get(b"bar\0").map(|sym| *sym);
- TestLib {
+ Ok(TestLib {
__library,
foo,
bar,
- }
+ })
}
pub unsafe fn foo(
&self,
diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs
index 81a045b5..ba0defaa 100644
--- a/tests/expectations/tests/dynamic_loading_with_class.rs
+++ b/tests/expectations/tests/dynamic_loading_with_class.rs
@@ -73,20 +73,20 @@ impl TestLib {
P: AsRef<::std::ffi::OsStr>,
{
let library = ::libloading::Library::new(path)?;
- Ok(Self::from_library(library))
+ Self::from_library(library)
}
- pub unsafe fn from_library<L>(library: L) -> Self
+ pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
where
L: Into<::libloading::Library>,
{
let __library = library.into();
let foo = __library.get(b"foo\0").map(|sym| *sym);
let bar = __library.get(b"bar\0").map(|sym| *sym);
- TestLib {
+ Ok(TestLib {
__library,
foo,
bar,
- }
+ })
}
pub unsafe fn foo(
&self,
diff --git a/tests/headers/dynamic_loading_required.h b/tests/headers/dynamic_loading_required.h
new file mode 100644
index 00000000..f9861e84
--- /dev/null
+++ b/tests/headers/dynamic_loading_required.h
@@ -0,0 +1,5 @@
+// bindgen-flags: --dynamic-loading TestLib --dynamic-link-require-all
+
+int foo(int x, int y);
+int bar(void *x);
+int baz();