Skip to content

Commit

Permalink
Add support for enums with the wrapped static functions feature (rust…
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau authored Feb 16, 2023
1 parent b865dbd commit 52a8cde
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ int takes_alias__extern(func f) asm("takes_alias__extern");
int takes_alias__extern(func f) { return takes_alias(f); }
int takes_qualified__extern(const int *const *arg) asm("takes_qualified__extern");
int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); }
enum foo takes_enum__extern(const enum foo f) asm("takes_enum__extern");
enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); }
6 changes: 6 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.

8 changes: 8 additions & 0 deletions bindgen-tests/tests/headers/wrap-static-fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ static inline int takes_alias(func f) {
static inline int takes_qualified(const int *const *arg) {
return **arg;
}

enum foo {
BAR = 0x0,
};

static inline enum foo takes_enum(const enum foo f) {
return f;
}
8 changes: 8 additions & 0 deletions bindgen/codegen/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ impl<'a> CSerialize<'a> for Type {
CompKind::Union => write!(writer, "union {}", name)?,
};
}
TypeKind::Enum(_enum_ty) => {
if self.is_const() {
write!(writer, "const ")?;
}

let name = item.canonical_name(ctx);
write!(writer, "enum {}", name)?;
}
ty => {
return Err(CodegenError::Serialize {
msg: format!("Cannot serialize type kind {:?}", ty),
Expand Down

0 comments on commit 52a8cde

Please sign in to comment.