Skip to content

Commit 785e066

Browse files
kanruemilio
authored andcommitted
Fix variadic arguments when used in function pointer
1 parent aa8ea65 commit 785e066

File tree

9 files changed

+28
-52
lines changed

9 files changed

+28
-52
lines changed

src/bindgen/ir/ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl Type {
417417
}
418418
syn::Type::BareFn(ref function) => {
419419
let mut wildcard_counter = 0;
420-
let args = function.inputs.iter().try_skip_map(|x| {
420+
let mut args = function.inputs.iter().try_skip_map(|x| {
421421
Type::load(&x.ty).map(|opt_ty| {
422422
opt_ty.map(|ty| {
423423
(
@@ -438,6 +438,9 @@ impl Type {
438438
})
439439
})
440440
})?;
441+
if function.variadic.is_some() {
442+
args.push((None, Type::Primitive(super::PrimitiveType::VaList)))
443+
}
441444
let (ret, never_return) = Type::load_from_output(&function.output)?;
442445
Type::FuncPtr {
443446
ret: Box::new(ret),

tests/expectations/va_list.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55

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

8-
typedef int32_t (*VaListFnPtr2)(int32_t count);
8+
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);
99

1010
typedef struct {
1111
int32_t (*fn1)(int32_t count, ...);
1212
} Interface_______i32_______i32_______va_list;
1313

14-
typedef struct {
15-
int32_t (*fn1)(int32_t count);
16-
} Interface_______i32_______i32;
17-
1814
int32_t va_list_test(int32_t count, ...);
1915

2016
int32_t va_list_test2(int32_t count, ...);
2117

2218
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
23-
int32_t (*fn2)(int32_t count),
19+
int32_t (*fn2)(int32_t count, ...),
2420
VaListFnPtr fn3,
2521
VaListFnPtr2 fn4,
2622
Interface_______i32_______i32_______va_list fn5,
27-
Interface_______i32_______i32 fn6);
23+
Interface_______i32_______i32_______va_list fn6);

tests/expectations/va_list.compat.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

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

8-
typedef int32_t (*VaListFnPtr2)(int32_t count);
8+
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);
99

1010
typedef struct {
1111
int32_t (*fn1)(int32_t count, ...);
1212
} Interface_______i32_______i32_______va_list;
1313

14-
typedef struct {
15-
int32_t (*fn1)(int32_t count);
16-
} Interface_______i32_______i32;
17-
1814
#ifdef __cplusplus
1915
extern "C" {
2016
#endif // __cplusplus
@@ -24,11 +20,11 @@ int32_t va_list_test(int32_t count, ...);
2420
int32_t va_list_test2(int32_t count, ...);
2521

2622
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
27-
int32_t (*fn2)(int32_t count),
23+
int32_t (*fn2)(int32_t count, ...),
2824
VaListFnPtr fn3,
2925
VaListFnPtr2 fn4,
3026
Interface_______i32_______i32_______va_list fn5,
31-
Interface_______i32_______i32 fn6);
27+
Interface_______i32_______i32_______va_list fn6);
3228

3329
#ifdef __cplusplus
3430
} // extern "C"

tests/expectations/va_list.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
using VaListFnPtr2 = int32_t(*)(int32_t count);
9+
using VaListFnPtr2 = int32_t(*)(int32_t count, ...);
1010

1111
template<typename T>
1212
struct Interface {
@@ -20,10 +20,10 @@ int32_t va_list_test(int32_t count, ...);
2020
int32_t va_list_test2(int32_t count, ...);
2121

2222
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
23-
int32_t (*fn2)(int32_t count),
23+
int32_t (*fn2)(int32_t count, ...),
2424
VaListFnPtr fn3,
2525
VaListFnPtr2 fn4,
2626
Interface<int32_t(*)(int32_t count, ...)> fn5,
27-
Interface<int32_t(*)(int32_t count)> fn6);
27+
Interface<int32_t(*)(int32_t count, ...)> fn6);
2828

2929
} // extern "C"

tests/expectations/va_list.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@ cdef extern from *:
88

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

11-
ctypedef int32_t (*VaListFnPtr2)(int32_t count);
11+
ctypedef int32_t (*VaListFnPtr2)(int32_t count, ...);
1212

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

16-
ctypedef struct Interface_______i32_______i32:
17-
int32_t (*fn1)(int32_t count);
18-
1916
int32_t va_list_test(int32_t count, ...);
2017

2118
int32_t va_list_test2(int32_t count, ...);
2219

2320
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
24-
int32_t (*fn2)(int32_t count),
21+
int32_t (*fn2)(int32_t count, ...),
2522
VaListFnPtr fn3,
2623
VaListFnPtr2 fn4,
2724
Interface_______i32_______i32_______va_list fn5,
28-
Interface_______i32_______i32 fn6);
25+
Interface_______i32_______i32_______va_list fn6);

tests/expectations/va_list_both.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55

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

8-
typedef int32_t (*VaListFnPtr2)(int32_t count);
8+
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);
99

1010
typedef struct Interface_______i32_______i32_______va_list {
1111
int32_t (*fn1)(int32_t count, ...);
1212
} Interface_______i32_______i32_______va_list;
1313

14-
typedef struct Interface_______i32_______i32 {
15-
int32_t (*fn1)(int32_t count);
16-
} Interface_______i32_______i32;
17-
1814
int32_t va_list_test(int32_t count, ...);
1915

2016
int32_t va_list_test2(int32_t count, ...);
2117

2218
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
23-
int32_t (*fn2)(int32_t count),
19+
int32_t (*fn2)(int32_t count, ...),
2420
VaListFnPtr fn3,
2521
VaListFnPtr2 fn4,
2622
struct Interface_______i32_______i32_______va_list fn5,
27-
struct Interface_______i32_______i32 fn6);
23+
struct Interface_______i32_______i32_______va_list fn6);

tests/expectations/va_list_both.compat.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

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

8-
typedef int32_t (*VaListFnPtr2)(int32_t count);
8+
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);
99

1010
typedef struct Interface_______i32_______i32_______va_list {
1111
int32_t (*fn1)(int32_t count, ...);
1212
} Interface_______i32_______i32_______va_list;
1313

14-
typedef struct Interface_______i32_______i32 {
15-
int32_t (*fn1)(int32_t count);
16-
} Interface_______i32_______i32;
17-
1814
#ifdef __cplusplus
1915
extern "C" {
2016
#endif // __cplusplus
@@ -24,11 +20,11 @@ int32_t va_list_test(int32_t count, ...);
2420
int32_t va_list_test2(int32_t count, ...);
2521

2622
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
27-
int32_t (*fn2)(int32_t count),
23+
int32_t (*fn2)(int32_t count, ...),
2824
VaListFnPtr fn3,
2925
VaListFnPtr2 fn4,
3026
struct Interface_______i32_______i32_______va_list fn5,
31-
struct Interface_______i32_______i32 fn6);
27+
struct Interface_______i32_______i32_______va_list fn6);
3228

3329
#ifdef __cplusplus
3430
} // extern "C"

tests/expectations/va_list_tag.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55

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

8-
typedef int32_t (*VaListFnPtr2)(int32_t count);
8+
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);
99

1010
struct Interface_______i32_______i32_______va_list {
1111
int32_t (*fn1)(int32_t count, ...);
1212
};
1313

14-
struct Interface_______i32_______i32 {
15-
int32_t (*fn1)(int32_t count);
16-
};
17-
1814
int32_t va_list_test(int32_t count, ...);
1915

2016
int32_t va_list_test2(int32_t count, ...);
2117

2218
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
23-
int32_t (*fn2)(int32_t count),
19+
int32_t (*fn2)(int32_t count, ...),
2420
VaListFnPtr fn3,
2521
VaListFnPtr2 fn4,
2622
struct Interface_______i32_______i32_______va_list fn5,
27-
struct Interface_______i32_______i32 fn6);
23+
struct Interface_______i32_______i32_______va_list fn6);

tests/expectations/va_list_tag.compat.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

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

8-
typedef int32_t (*VaListFnPtr2)(int32_t count);
8+
typedef int32_t (*VaListFnPtr2)(int32_t count, ...);
99

1010
struct Interface_______i32_______i32_______va_list {
1111
int32_t (*fn1)(int32_t count, ...);
1212
};
1313

14-
struct Interface_______i32_______i32 {
15-
int32_t (*fn1)(int32_t count);
16-
};
17-
1814
#ifdef __cplusplus
1915
extern "C" {
2016
#endif // __cplusplus
@@ -24,11 +20,11 @@ int32_t va_list_test(int32_t count, ...);
2420
int32_t va_list_test2(int32_t count, ...);
2521

2622
void va_list_fn_ptrs(int32_t (*fn1)(int32_t count, ...),
27-
int32_t (*fn2)(int32_t count),
23+
int32_t (*fn2)(int32_t count, ...),
2824
VaListFnPtr fn3,
2925
VaListFnPtr2 fn4,
3026
struct Interface_______i32_______i32_______va_list fn5,
31-
struct Interface_______i32_______i32 fn6);
27+
struct Interface_______i32_______i32_______va_list fn6);
3228

3329
#ifdef __cplusplus
3430
} // extern "C"

0 commit comments

Comments
 (0)