From 52a8cde6a4ddd5dd9e130f2874816d4afd910cb0 Mon Sep 17 00:00:00 2001 From: Urgau <3616612+Urgau@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:13:54 +0100 Subject: Add support for enums with the wrapped static functions feature (#2415) --- .../tests/expectations/tests/generated/wrap_static_fns.c | 2 ++ bindgen-tests/tests/expectations/tests/wrap-static-fns.rs | 6 ++++++ bindgen-tests/tests/headers/wrap-static-fns.h | 8 ++++++++ bindgen/codegen/serialize.rs | 8 ++++++++ 4 files changed, 24 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 22b2f67f..f5f33f84 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -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); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 54ed9fd4..fbfdcb13 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -50,3 +50,9 @@ extern "C" { arg: *const *const ::std::os::raw::c_int, ) -> ::std::os::raw::c_int; } +pub const foo_BAR: foo = 0; +pub type foo = ::std::os::raw::c_uint; +extern "C" { + #[link_name = "\u{1}takes_enum__extern"] + pub fn takes_enum(f: foo) -> foo; +} diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 8b90c7bc..03892315 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -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; +} diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index e521c703..13106484 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -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), -- cgit v1.2.3