Skip to content

Commit 1a09f45

Browse files
authored
Use void in parameterless functions (#2633)
* Use void for parameterless function arguments * Update tests * Update CHANGELOG.md
1 parent 53c01d2 commit 1a09f45

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@
179179

180180
## Added
181181
## Changed
182+
- The `--wrap-static-fns` feature was updated so function types that has no
183+
argument use `void` as its sole argument.
182184
## Removed
183185
## Fixed
184186
## Security

bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ int takes_alias__extern(func f) { return takes_alias(f); }
1111
int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); }
1212
enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); }
1313
void nevermore__extern(void) { nevermore(); }
14+
int takes_fn_with_no_args__extern(int (f) (void)) { return takes_fn_with_no_args(f); }
1415
void no_extra_argument__extern(__builtin_va_list va) { no_extra_argument(va); }
1516
int many_va_list__extern(int i, __builtin_va_list va1, __builtin_va_list va2) { return many_va_list(i, va1, va2); }
1617
int wrap_as_variadic_fn1__extern(int i, ...) {

bindgen-tests/tests/expectations/tests/wrap-static-fns.rs

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/headers/wrap-static-fns.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ static inline void nevermore() {
5252
while (1) { }
5353
}
5454

55+
static inline int takes_fn_with_no_args(int(f)(void)) {
56+
return f();
57+
}
58+
5559
static inline int variadic(int x, ...) {
5660
return x;
5761
}

bindgen/codegen/serialize.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,26 @@ impl<'a> CSerialize<'a> for Type {
322322
}
323323
write!(writer, ")")?;
324324

325-
write!(writer, " (")?;
326-
serialize_sep(
327-
", ",
328-
signature.argument_types().iter(),
329-
ctx,
330-
writer,
331-
|(name, type_id), ctx, buf| {
332-
let mut stack = vec![];
333-
if let Some(name) = name {
334-
stack.push(name.clone());
335-
}
336-
type_id.serialize(ctx, (), &mut stack, buf)
337-
},
338-
)?;
339-
write!(writer, ")")?
325+
let args = signature.argument_types();
326+
if args.is_empty() {
327+
write!(writer, " (void)")?;
328+
} else {
329+
write!(writer, " (")?;
330+
serialize_sep(
331+
", ",
332+
args.iter(),
333+
ctx,
334+
writer,
335+
|(name, type_id), ctx, buf| {
336+
let mut stack = vec![];
337+
if let Some(name) = name {
338+
stack.push(name.clone());
339+
}
340+
type_id.serialize(ctx, (), &mut stack, buf)
341+
},
342+
)?;
343+
write!(writer, ")")?
344+
}
340345
}
341346
TypeKind::ResolvedTypeRef(type_id) => {
342347
if self.is_const() {

0 commit comments

Comments
 (0)