Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variadic arguments when used in function pointer #971

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl Type {
}
syn::Type::BareFn(ref function) => {
let mut wildcard_counter = 0;
let args = function.inputs.iter().try_skip_map(|x| {
let mut args = function.inputs.iter().try_skip_map(|x| {
Type::load(&x.ty).map(|opt_ty| {
opt_ty.map(|ty| {
(
Expand All @@ -438,6 +438,9 @@ impl Type {
})
})
})?;
if function.variadic.is_some() {
args.push((None, Type::Primitive(super::PrimitiveType::VaList)))
}
let (ret, never_return) = Type::load_from_output(&function.output)?;
Type::FuncPtr {
ret: Box::new(ret),
Expand Down
10 changes: 3 additions & 7 deletions tests/expectations/va_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@

typedef int32_t (*VaListFnPtr)(int32_t count, ...);

typedef int32_t (*VaListFnPtr2)(int32_t count);
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);

typedef struct {
int32_t (*fn1)(int32_t count, ...);
} Interface_______i32_______i32_______va_list;

typedef struct {
int32_t (*fn1)(int32_t count);
} Interface_______i32_______i32;

int32_t va_list_test(int32_t count, ...);

int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
Interface_______i32_______i32_______va_list fn5,
Interface_______i32_______i32 fn6);
Interface_______i32_______i32_______va_list fn6);
10 changes: 3 additions & 7 deletions tests/expectations/va_list.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@

typedef int32_t (*VaListFnPtr)(int32_t count, ...);

typedef int32_t (*VaListFnPtr2)(int32_t count);
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);

typedef struct {
int32_t (*fn1)(int32_t count, ...);
} Interface_______i32_______i32_______va_list;

typedef struct {
int32_t (*fn1)(int32_t count);
} Interface_______i32_______i32;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
Expand All @@ -24,11 +20,11 @@ int32_t va_list_test(int32_t count, ...);
int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
Interface_______i32_______i32_______va_list fn5,
Interface_______i32_______i32 fn6);
Interface_______i32_______i32_______va_list fn6);

#ifdef __cplusplus
} // extern "C"
Expand Down
6 changes: 3 additions & 3 deletions tests/expectations/va_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using VaListFnPtr = int32_t(*)(int32_t count, ...);

using VaListFnPtr2 = int32_t(*)(int32_t count);
using VaListFnPtr2 = int32_t(*)(int32_t count, ...);

template<typename T>
struct Interface {
Expand All @@ -20,10 +20,10 @@ int32_t va_list_test(int32_t count, ...);
int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
Interface<int32_t(*)(int32_t count, ...)> fn5,
Interface<int32_t(*)(int32_t count)> fn6);
Interface<int32_t(*)(int32_t count, ...)> fn6);

} // extern "C"
9 changes: 3 additions & 6 deletions tests/expectations/va_list.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ cdef extern from *:

ctypedef int32_t (*VaListFnPtr)(int32_t count, ...);

ctypedef int32_t (*VaListFnPtr2)(int32_t count);
ctypedef int32_t (*VaListFnPtr2)(int32_t count, ...);

ctypedef struct Interface_______i32_______i32_______va_list:
int32_t (*fn1)(int32_t count, ...);

ctypedef struct Interface_______i32_______i32:
int32_t (*fn1)(int32_t count);

int32_t va_list_test(int32_t count, ...);

int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
Interface_______i32_______i32_______va_list fn5,
Interface_______i32_______i32 fn6);
Interface_______i32_______i32_______va_list fn6);
10 changes: 3 additions & 7 deletions tests/expectations/va_list_both.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@

typedef int32_t (*VaListFnPtr)(int32_t count, ...);

typedef int32_t (*VaListFnPtr2)(int32_t count);
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);

typedef struct Interface_______i32_______i32_______va_list {
int32_t (*fn1)(int32_t count, ...);
} Interface_______i32_______i32_______va_list;

typedef struct Interface_______i32_______i32 {
int32_t (*fn1)(int32_t count);
} Interface_______i32_______i32;

int32_t va_list_test(int32_t count, ...);

int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
struct Interface_______i32_______i32_______va_list fn5,
struct Interface_______i32_______i32 fn6);
struct Interface_______i32_______i32_______va_list fn6);
10 changes: 3 additions & 7 deletions tests/expectations/va_list_both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@

typedef int32_t (*VaListFnPtr)(int32_t count, ...);

typedef int32_t (*VaListFnPtr2)(int32_t count);
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);

typedef struct Interface_______i32_______i32_______va_list {
int32_t (*fn1)(int32_t count, ...);
} Interface_______i32_______i32_______va_list;

typedef struct Interface_______i32_______i32 {
int32_t (*fn1)(int32_t count);
} Interface_______i32_______i32;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
Expand All @@ -24,11 +20,11 @@ int32_t va_list_test(int32_t count, ...);
int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
struct Interface_______i32_______i32_______va_list fn5,
struct Interface_______i32_______i32 fn6);
struct Interface_______i32_______i32_______va_list fn6);

#ifdef __cplusplus
} // extern "C"
Expand Down
10 changes: 3 additions & 7 deletions tests/expectations/va_list_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@

typedef int32_t (*VaListFnPtr)(int32_t count, ...);

typedef int32_t (*VaListFnPtr2)(int32_t count);
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);

struct Interface_______i32_______i32_______va_list {
int32_t (*fn1)(int32_t count, ...);
};

struct Interface_______i32_______i32 {
int32_t (*fn1)(int32_t count);
};

int32_t va_list_test(int32_t count, ...);

int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
struct Interface_______i32_______i32_______va_list fn5,
struct Interface_______i32_______i32 fn6);
struct Interface_______i32_______i32_______va_list fn6);
10 changes: 3 additions & 7 deletions tests/expectations/va_list_tag.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@

typedef int32_t (*VaListFnPtr)(int32_t count, ...);

typedef int32_t (*VaListFnPtr2)(int32_t count);
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);

struct Interface_______i32_______i32_______va_list {
int32_t (*fn1)(int32_t count, ...);
};

struct Interface_______i32_______i32 {
int32_t (*fn1)(int32_t count);
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
Expand All @@ -24,11 +20,11 @@ int32_t va_list_test(int32_t count, ...);
int32_t va_list_test2(int32_t count, ...);

void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
int32_t (*fn2)(int32_t count),
int32_t (*fn2)(int32_t count, ...),
VaListFnPtr fn3,
VaListFnPtr2 fn4,
struct Interface_______i32_______i32_______va_list fn5,
struct Interface_______i32_______i32 fn6);
struct Interface_______i32_______i32_______va_list fn6);

#ifdef __cplusplus
} // extern "C"
Expand Down
Loading