summaryrefslogtreecommitdiff
path: root/bindgen-integration/src/lib.rs
diff options
context:
space:
mode:
authorChristian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com>2023-02-07 10:13:48 -0500
committerGitHub <noreply@github.com>2023-02-07 10:13:48 -0500
commit2be14a33451b0259bfed8e0fe517502e46fab7b6 (patch)
treec2775e75c393aab280598bb763db52d4859ccc3d /bindgen-integration/src/lib.rs
parent62b48c56703eb5f734b9a333b1ae2be10ffa303e (diff)
Generate extern wrappers for inlined functions (#2335)
* Generate extern wrappers for inlined functions If bindgen finds an inlined function and the `--generate-extern-functions` options is enabled, then: - It will generate two new source and header files with external functions that wrap the inlined functions. - Rerun `Bindings::generate` using the new header file to include these wrappers in the generated bindings. The following additional options were added: - `--extern-function-suffix=<suffix>`: Adds <suffix> to the name of each external wrapper function (`__extern` is used by default). - `--extern-functions-file-name=<name>`: Uses <name> as the file name for the header and source files (`extern` is used by default). - `--extern-function-directory=<dir>`: Creates the source and header files inside <dir> (`/tmp/bindgen` is used by default). The C code serialization is experimental and only supports a very limited set of C functions. Fixes #1090. --------- Co-authored-by: Amanjeev Sethi <aj@amanjeev.com>
Diffstat (limited to 'bindgen-integration/src/lib.rs')
-rwxr-xr-xbindgen-integration/src/lib.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs
index 43f71580..e89351c3 100755
--- a/bindgen-integration/src/lib.rs
+++ b/bindgen-integration/src/lib.rs
@@ -4,6 +4,10 @@ mod bindings {
include!(concat!(env!("OUT_DIR"), "/test.rs"));
}
+mod extern_bindings {
+ include!(concat!(env!("OUT_DIR"), "/extern.rs"));
+}
+
use std::ffi::CStr;
use std::mem;
use std::os::raw::c_int;
@@ -286,3 +290,35 @@ fn test_custom_derive() {
assert!(meter < lightyear);
assert!(meter > micron);
}
+
+#[test]
+fn test_wrap_static_fns() {
+ // GH-1090: https://github.com/rust-lang/rust-bindgen/issues/1090
+ unsafe {
+ let f = extern_bindings::foo();
+ assert_eq!(11, f);
+
+ let b = extern_bindings::bar();
+ assert_eq!(1, b);
+
+ let t = extern_bindings::takes_ptr(&mut 1);
+ assert_eq!(2, t);
+
+ extern "C" fn function(x: i32) -> i32 {
+ x + 1
+ }
+
+ let tp = extern_bindings::takes_fn_ptr(Some(function));
+ assert_eq!(2, tp);
+
+ let tf = extern_bindings::takes_fn(Some(function));
+ assert_eq!(3, tf);
+
+ let ta = extern_bindings::takes_alias(Some(function));
+ assert_eq!(4, ta);
+
+ let tq =
+ extern_bindings::takes_qualified(&(&5 as *const _) as *const _);
+ assert_eq!(5, tq);
+ }
+}