forked from rust-lang/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this includes comments and must_use annotations
- Loading branch information
1 parent
310f7f8
commit 9689aec
Showing
4 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#![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 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 baz = __library.get(b"baz\0").map(|sym| *sym)?; | ||
Ok(TestLib { | ||
__library, | ||
foo, | ||
baz, | ||
}) | ||
} | ||
#[must_use] | ||
#[doc = " @brief A function"] | ||
#[doc = ""] | ||
#[doc = " @param x"] | ||
#[doc = " @param y"] | ||
#[doc = " @return int"] | ||
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 baz(&self) -> ::std::os::raw::c_int { | ||
(self.baz)() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// bindgen-flags: --dynamic-loading TestLib --dynamic-link-require-all --enable-function-attribute-detection | ||
/** | ||
* @brief A function | ||
* | ||
* @param x | ||
* @param y | ||
* @return int | ||
*/ | ||
__attribute__((warn_unused_result)) | ||
int foo(int x, int y); | ||
int baz() ; |