From 97a42922149c9912c8fa9f653b6015a6745f42e8 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 18 Apr 2023 15:26:32 +0200 Subject: [PATCH] Add tests for wrapped va_list fn as variadic --- .../tests/generated/wrap_static_fns.c | 18 ++++++++++ .../expectations/tests/wrap-static-fns.rs | 33 +++++++++++++++++++ bindgen-tests/tests/headers/wrap-static-fns.h | 13 ++++++++ bindgen-tests/tests/parse_callbacks/mod.rs | 10 ++++++ bindgen-tests/tests/tests.rs | 1 + 5 files changed, 75 insertions(+) diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 8d6e97aad1..8f2541bac0 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -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); +} diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 2800d7034d..96e59454e0 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -60,3 +60,36 @@ extern "C" { #[link_name = "nevermore__extern"] pub fn nevermore(); } +extern "C" { + #[link_name = "no_extra_argument__extern"] + pub fn no_extra_argument(va: *mut __va_list_tag); +} +extern "C" { + #[link_name = "many_va_list__extern"] + pub fn many_va_list( + i: ::std::os::raw::c_int, + va1: *mut __va_list_tag, + va2: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "wrap_as_variadic_fn1__extern"] + pub fn wrap_as_variadic_fn1_wrapped( + i: ::std::os::raw::c_int, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "wrap_as_variadic_fn2__extern"] + pub fn wrap_as_variadic_fn2_wrapped(i: ::std::os::raw::c_int, ...); +} +pub type __builtin_va_list = [__va_list_tag; 1usize]; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __va_list_tag { + pub gp_offset: ::std::os::raw::c_uint, + pub fp_offset: ::std::os::raw::c_uint, + pub overflow_arg_area: *mut ::std::os::raw::c_void, + pub reg_save_area: *mut ::std::os::raw::c_void, + _unused: [u8; 0], +} diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 85dfeac2af..b960ccc90c 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -1,4 +1,5 @@ // bindgen-flags: --experimental --wrap-static-fns +// bindgen-parse-callbacks: wrap-as-variadic-fn static inline int foo() { return 11; @@ -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) {} diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 85082b63f7..a2963abe11 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -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 { + Some(name.to_owned() + "_wrapped") + } +} + pub fn lookup(cb: &str) -> Box { 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 diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index e1c35faa41..8a62dfba74 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -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");