Skip to content

Commit

Permalink
Add tests for wrapped va_list fn as variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Apr 18, 2023
1 parent 08da50e commit c9f17d7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ int takes_alias__extern(func f) { return takes_alias(f); }
int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); }
enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); }
void nevermore__extern(void) { nevermore(); }
void no_extra_argument__extern(__builtin_va_list va) { no_extra_argument(va); }
int many_va_list__extern(int i, __builtin_va_list va1, __builtin_va_list va2) { return many_va_list(i, va1, va2); }
int wrap_as_variadic_fn1__extern(int i, ...) {
int ret;
va_list ap;

va_start(ap, i);
ret = wrap_as_variadic_fn1(i, ap);
va_end(ap);
return ret;
}
void wrap_as_variadic_fn2__extern(int i, ...) {
va_list ap;

va_start(ap, i);
wrap_as_variadic_fn2(i, ap);
va_end(ap);
}
33 changes: 33 additions & 0 deletions bindgen-tests/tests/expectations/tests/wrap-static-fns.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions bindgen-tests/tests/headers/wrap-static-fns.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// bindgen-flags: --experimental --wrap-static-fns
// bindgen-parse-callbacks: wrap-as-variadic-fn

static inline int foo() {
return 11;
Expand Down Expand Up @@ -48,3 +49,15 @@ static inline void nevermore() {
static inline int variadic(int x, ...) {
return x;
}

static inline void no_extra_argument(__builtin_va_list va) {}

static inline int many_va_list(int i, __builtin_va_list va1, __builtin_va_list va2) {
return i;
}

static inline int wrap_as_variadic_fn1(int i, __builtin_va_list va) {
return i;
}

static inline void wrap_as_variadic_fn2(int i, __builtin_va_list va) {}
10 changes: 10 additions & 0 deletions bindgen-tests/tests/parse_callbacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ impl ParseCallbacks for BlocklistedTypeImplementsTrait {
}
}

#[derive(Debug)]
pub(super) struct WrapAsVariadicFn;

impl ParseCallbacks for WrapAsVariadicFn {
fn wrap_as_variadic_fn(&self, name: &str) -> Option<String> {
Some(name.to_owned() + "_wrapped")
}
}

pub fn lookup(cb: &str) -> Box<dyn ParseCallbacks> {
match cb {
"enum-variant-rename" => Box::new(EnumVariantRename),
"blocklisted-type-implements-trait" => {
Box::new(BlocklistedTypeImplementsTrait)
}
"wrap-as-variadic-fn" => Box::new(WrapAsVariadicFn),
call_back => {
if call_back.starts_with("remove-function-prefix-") {
let prefix = call_back
Expand Down
1 change: 1 addition & 0 deletions bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ fn test_wrap_static_fns() {
.header("tests/headers/wrap-static-fns.h")
.wrap_static_fns(true)
.wrap_static_fns_path(generated_path.display().to_string())
.parse_callbacks(Box::new(parse_callbacks::WrapAsVariadicFn))
.generate()
.expect("Failed to generate bindings");

Expand Down

0 comments on commit c9f17d7

Please sign in to comment.