From 8c41d550c1f6512d41e9765f771a0e84d7b85031 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Tue, 6 Aug 2024 15:29:26 -0400 Subject: [PATCH] Add option to generate safe and unsafe conversions for rustified enums --- bindgen-cli/options.rs | 38 +- bindgen-integration/build.rs | 2 + .../tests/expectations/tests/anon_enum.rs | 5 + .../expectations/tests/anon_enum_allowlist.rs | 3 + .../expectations/tests/anon_enum_trait.rs | 4 + .../tests/expectations/tests/anon_union.rs | 2 + .../expectations/tests/anon_union_1_0.rs | 2 + .../expectations/tests/bitfield_align_2.rs | 5 + .../tests/class_with_inner_struct.rs | 5 + .../tests/class_with_inner_struct_1_0.rs | 5 + .../expectations/tests/const_enum_unnamed.rs | 5 + .../expectations/tests/constant-evaluate.rs | 3 + .../tests/expectations/tests/constify-enum.rs | 7 + .../expectations/tests/derive-custom-cli.rs | 2 + .../tests/dupe-enum-variant-in-namespace.rs | 3 + .../tests/expectations/tests/empty-enum.rs | 3 + .../expectations/tests/enum-default-rust.rs | 12 + .../expectations/tests/enum-doc-rusty.rs | 16 + .../expectations/tests/enum-no-debug-rust.rs | 12 + .../expectations/tests/enum-undefault.rs | 3 + .../tests/expectations/tests/enum_alias.rs | 2 + .../tests/enum_and_vtable_mangling.rs | 3 + .../tests/expectations/tests/enum_dupe.rs | 2 + .../expectations/tests/enum_explicit_type.rs | 22 + .../tests/enum_in_template_with_typedef.rs | 2 + .../tests/expectations/tests/enum_negative.rs | 3 + .../tests/expectations/tests/enum_packed.rs | 9 + .../expectations/tests/forward-enum-decl.rs | 3 + .../expectations/tests/func_ptr_in_struct.rs | 1 + .../tests/issue-1198-alias-rust-enum.rs | 6 + .../tests/issue-1488-enum-new-type.rs | 3 + .../tests/expectations/tests/issue-1554.rs | 3 + .../tests/expectations/tests/issue-2646.rs | 101 +++++ .../tests/expectations/tests/issue-372.rs | 13 + .../tests/expectations/tests/issue-410.rs | 1 + .../tests/expectations/tests/issue-493.rs | 4 + .../tests/expectations/tests/issue-493_1_0.rs | 4 + ...ate-params-causing-layout-test-failures.rs | 3 + .../tests/issue-888-enum-var-decl-jump.rs | 1 + .../expectations/tests/jsval_layout_opaque.rs | 71 +++ .../tests/jsval_layout_opaque_1_0.rs | 71 +++ .../tests/layout_array_too_long.rs | 8 + .../tests/layout_cmdline_token.rs | 9 + .../expectations/tests/layout_eth_conf.rs | 72 +++ .../expectations/tests/layout_eth_conf_1_0.rs | 72 +++ .../tests/layout_large_align_field.rs | 8 + .../tests/libclang-9/struct_typedef_ns.rs | 4 + .../expectations/tests/nsStyleAutoArray.rs | 2 + .../tests/expectations/tests/ord-enum.rs | 10 + .../expectations/tests/overflowed_enum.rs | 7 + .../tests/prepend-enum-constified-variant.rs | 2 + .../tests/expectations/tests/short-enums.rs | 6 + .../expectations/tests/struct_typedef.rs | 4 + .../expectations/tests/struct_typedef_ns.rs | 4 + .../expectations/tests/weird_bitfields.rs | 4 + bindgen-tests/tests/headers/issue-2646.h | 30 ++ bindgen/.lib.rs.swp | Bin 0 -> 81920 bytes bindgen/codegen/mod.rs | 419 +++++++++++++----- bindgen/ir/enum_ty.rs | 102 ++++- bindgen/lib.rs | 17 +- bindgen/options/mod.rs | 17 +- 61 files changed, 1116 insertions(+), 146 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-2646.rs create mode 100644 bindgen-tests/tests/headers/issue-2646.h create mode 100644 bindgen/.lib.rs.swp diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index cd5e9bb127..38d891293f 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -2,7 +2,8 @@ use bindgen::callbacks::TypeKind; use bindgen::{ builder, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, - RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, + RegexSet, RustEnumOptions, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, + RUST_TARGET_STRINGS, }; use clap::error::{Error, ErrorKind}; use clap::{CommandFactory, Parser}; @@ -75,6 +76,21 @@ fn parse_abi_override(abi_override: &str) -> Result<(Abi, String), Error> { Ok((abi, regex.to_owned())) } +fn parse_rustified_enum( + rustified_enum: &str, +) -> Result<(RustEnumOptions, String), Error> { + let (regex, options) = match rustified_enum.rsplit_once('=') { + Some((regex, options)) => (regex, options), + None => (rustified_enum, ""), + }; + + let options = options + .parse() + .map_err(|err| Error::raw(ErrorKind::InvalidValue, err))?; + + Ok((options, regex.to_owned())) +} + fn parse_custom_derive( custom_derive: &str, ) -> Result<(Vec, String), Error> { @@ -111,12 +127,11 @@ struct BindgenCommand { /// Mark any enum whose name matches REGEX as a global newtype. #[arg(long, value_name = "REGEX")] newtype_global_enum: Vec, - /// Mark any enum whose name matches REGEX as a Rust enum. - #[arg(long, value_name = "REGEX")] - rustified_enum: Vec, - /// Mark any enum whose name matches REGEX as a non-exhaustive Rust enum. - #[arg(long, value_name = "REGEX")] - rustified_non_exhaustive_enum: Vec, + /// Mark any enum whose name matches the provided regex as a Rust enum. This parameter takes + /// options in the shape REGEX or REGEX=OPTIONS where OPTIONS can be a comma separated list of + /// options from non_exhaustive, try_from_raw, and from_raw_unchecked. + #[arg(long, value_parser = parse_rustified_enum)] + rustified_enum: Vec<(RustEnumOptions, String)>, /// Mark any enum whose name matches REGEX as a series of constants. #[arg(long, value_name = "REGEX")] constified_enum: Vec, @@ -472,7 +487,6 @@ where newtype_enum, newtype_global_enum, rustified_enum, - rustified_non_exhaustive_enum, constified_enum, constified_enum_module, default_macro_constant_type, @@ -635,12 +649,8 @@ where builder = builder.newtype_global_enum(regex); } - for regex in rustified_enum { - builder = builder.rustified_enum(regex); - } - - for regex in rustified_non_exhaustive_enum { - builder = builder.rustified_non_exhaustive_enum(regex); + for (options, regex) in rustified_enum { + builder = builder.rustified_enum(options, regex); } for regex in constified_enum { diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 6b06c91bc3..c90411e43f 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -180,6 +180,8 @@ fn setup_macro_test() { .enable_cxx_namespaces() .default_enum_style(EnumVariation::Rust { non_exhaustive: false, + safe_conversion: false, + unsafe_conversion: false, }) .raw_line("pub use self::root::*;") .raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }") diff --git a/bindgen-tests/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs index c3790a2a24..209a0a1a11 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum.rs @@ -6,6 +6,8 @@ pub struct Test { pub bar: f32, } pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; +pub type Test__bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const Test__bindgen_ty_1_T_NONE: Test__bindgen_ty_1_ctype = 0; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Test__bindgen_ty_1 { @@ -18,6 +20,9 @@ const _: () = { ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize]; ["Offset of field: Test::bar"][::std::mem::offset_of!(Test, bar) - 4usize]; }; +pub type Baz_ctype = ::std::os::raw::c_uint; +pub const Baz_Foo: Baz_ctype = 0; +pub const Baz_Bar: Baz_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Baz { diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs index 4b172d7aeb..63b8d01255 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs @@ -1,6 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO; pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const _bindgen_ty_1_NODE_FLAG_FOO: _bindgen_ty_1_ctype = 0; +pub const _bindgen_ty_1_NODE_FLAG_BAR: _bindgen_ty_1_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs index cfd4d03200..312e200901 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs @@ -13,6 +13,8 @@ pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::gener pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub type DataType__bindgen_ty_1_ctype = i32; +pub const DataType__bindgen_ty_1_generic_type: DataType__bindgen_ty_1_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum DataType__bindgen_ty_1 { @@ -25,6 +27,8 @@ pub struct Foo { } pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; +pub type Foo__bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const Foo__bindgen_ty_1_Bar: Foo__bindgen_ty_1_ctype = 0; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo__bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs index d9bf3cf183..4c9947e0c3 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union.rs @@ -9,6 +9,8 @@ pub struct TErrorResult { impl TErrorResult_UnionState { pub const HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; } +pub type TErrorResult_UnionState_ctype = i32; +pub const TErrorResult_UnionState_HasMessage: TErrorResult_UnionState_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum TErrorResult_UnionState { diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index 29b13d010d..f223fa893b 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -51,6 +51,8 @@ pub struct TErrorResult { pub mUnionState: TErrorResult_UnionState, } pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; +pub type TErrorResult_UnionState_ctype = i32; +pub const TErrorResult_UnionState_HasMessage: TErrorResult_UnionState_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum TErrorResult_UnionState { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index b87af0c99c..1465c596a3 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -84,6 +84,11 @@ where } } } +pub type MyEnum_ctype = ::std::os::raw::c_uint; +pub const MyEnum_ONE: MyEnum_ctype = 0; +pub const MyEnum_TWO: MyEnum_ctype = 1; +pub const MyEnum_THREE: MyEnum_ctype = 2; +pub const MyEnum_FOUR: MyEnum_ctype = 3; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MyEnum { diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs index 710026c72f..4436b64803 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs @@ -107,6 +107,11 @@ const _: () = { ["Alignment of B"][::std::mem::align_of::() - 4usize]; ["Offset of field: B::d"][::std::mem::offset_of!(B, d) - 0usize]; }; +pub type StepSyntax_ctype = ::std::os::raw::c_int; +pub const StepSyntax_Keyword: StepSyntax_ctype = 0; +pub const StepSyntax_FunctionalWithoutKeyword: StepSyntax_ctype = 1; +pub const StepSyntax_FunctionalWithStartKeyword: StepSyntax_ctype = 2; +pub const StepSyntax_FunctionalWithEndKeyword: StepSyntax_ctype = 3; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum StepSyntax { diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index 23afad6319..aff7ace03f 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -211,6 +211,11 @@ impl Clone for B { *self } } +pub type StepSyntax_ctype = ::std::os::raw::c_int; +pub const StepSyntax_Keyword: StepSyntax_ctype = 0; +pub const StepSyntax_FunctionalWithoutKeyword: StepSyntax_ctype = 1; +pub const StepSyntax_FunctionalWithStartKeyword: StepSyntax_ctype = 2; +pub const StepSyntax_FunctionalWithEndKeyword: StepSyntax_ctype = 3; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum StepSyntax { diff --git a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs index f49d825224..bdb814d727 100644 --- a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs +++ b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs @@ -1,6 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const _bindgen_ty_1_FOO_BAR: _bindgen_ty_1_ctype = 0; +pub const _bindgen_ty_1_FOO_BAZ: _bindgen_ty_1_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { @@ -13,6 +16,8 @@ pub struct Foo { pub _address: u8, } pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; +pub type Foo__bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const Foo__bindgen_ty_1_FOO_BAR: Foo__bindgen_ty_1_ctype = 10; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo__bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/constant-evaluate.rs index bbcf6d5450..69f4a08b76 100644 --- a/bindgen-tests/tests/expectations/tests/constant-evaluate.rs +++ b/bindgen-tests/tests/expectations/tests/constant-evaluate.rs @@ -1,6 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const _bindgen_ty_1_foo: _bindgen_ty_1_ctype = 4; +pub const _bindgen_ty_1_bar: _bindgen_ty_1_ctype = 8; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/constify-enum.rs b/bindgen-tests/tests/expectations/tests/constify-enum.rs index 67d2749c51..8ba7ba0146 100644 --- a/bindgen-tests/tests/expectations/tests/constify-enum.rs +++ b/bindgen-tests/tests/expectations/tests/constify-enum.rs @@ -3,6 +3,13 @@ pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSProper impl nsCSSPropertyID { pub const eCSSProperty_COUNT: nsCSSPropertyID = nsCSSPropertyID::eCSSPropertyAlias_aa; } +pub type nsCSSPropertyID_ctype = ::std::os::raw::c_uint; +pub const nsCSSPropertyID_eCSSProperty_a: nsCSSPropertyID_ctype = 0; +pub const nsCSSPropertyID_eCSSProperty_b: nsCSSPropertyID_ctype = 1; +pub const nsCSSPropertyID_eCSSPropertyAlias_aa: nsCSSPropertyID_ctype = 2; +pub const nsCSSPropertyID_eCSSPropertyAlias_bb: nsCSSPropertyID_ctype = 3; +///<
+pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSPropertyID_ctype = 4; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum nsCSSPropertyID { diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs index 59a3a76571..591d4ecd23 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -12,6 +12,8 @@ const _: () = { "Offset of field: foo_struct::inner", ][::std::mem::offset_of!(foo_struct, inner) - 0usize]; }; +pub type foo_enum_ctype = ::std::os::raw::c_uint; +pub const foo_enum_inner: foo_enum_ctype = 0; #[repr(u32)] #[derive(Clone, Hash, PartialEq, Eq, Copy)] pub enum foo_enum { diff --git a/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs index d521bcc17b..7448ba4b43 100644 --- a/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs @@ -12,6 +12,9 @@ pub mod root { impl root::foo::Bar { pub const Foo3: root::foo::Bar = Bar::Foo2; } + pub type Bar_ctype = ::std::os::raw::c_uint; + pub const Bar_Foo: Bar_ctype = 0; + pub const Bar_Foo2: Bar_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { diff --git a/bindgen-tests/tests/expectations/tests/empty-enum.rs b/bindgen-tests/tests/expectations/tests/empty-enum.rs index fda6f581df..4af61e09f2 100644 --- a/bindgen-tests/tests/expectations/tests/empty-enum.rs +++ b/bindgen-tests/tests/expectations/tests/empty-enum.rs @@ -1,5 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type EmptyConstified = ::std::os::raw::c_uint; +pub type EmptyRustified_ctype = ::std::os::raw::c_uint; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum EmptyRustified { @@ -8,6 +9,7 @@ pub enum EmptyRustified { pub mod EmptyModule { pub type Type = ::std::os::raw::c_uint; } +pub type EmptyClassRustified_ctype = ::std::os::raw::c_char; #[repr(i8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum EmptyClassRustified { @@ -17,6 +19,7 @@ pub type EmptyClassConstified = ::std::os::raw::c_char; pub mod EmptyClassModule { pub type Type = ::std::os::raw::c_char; } +pub type ForwardClassRustified_ctype = ::std::os::raw::c_char; #[repr(i8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum ForwardClassRustified { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index f9a99166de..80f297fd2e 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -6,6 +6,9 @@ pub struct foo { } pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; +pub type foo__bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const foo__bindgen_ty_1_FOO_A: foo__bindgen_ty_1_ctype = 0; +pub const foo__bindgen_ty_1_FOO_B: foo__bindgen_ty_1_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum foo__bindgen_ty_1 { @@ -27,6 +30,9 @@ impl Default for foo { } } } +pub type Foo_ctype = ::std::os::raw::c_uint; +pub const Foo_Bar: Foo_ctype = 0; +pub const Foo_Qux: Foo_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { @@ -38,6 +44,9 @@ pub mod Neg { pub const MinusOne: Type = -1; pub const One: Type = 1; } +pub type NoDebug_ctype = ::std::os::raw::c_uint; +pub const NoDebug_NoDebug1: NoDebug_ctype = 0; +pub const NoDebug_NoDebug2: NoDebug_ctype = 1; #[repr(u32)] ///
#[derive(Copy, Clone, Hash, PartialEq, Eq)] @@ -45,6 +54,9 @@ pub enum NoDebug { NoDebug1 = 0, NoDebug2 = 1, } +pub type Debug_ctype = ::std::os::raw::c_uint; +pub const Debug_Debug1: Debug_ctype = 0; +pub const Debug_Debug2: Debug_ctype = 1; #[repr(u32)] ///
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs index 3eec0759c5..21435b0bd7 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs @@ -1,4 +1,20 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type B_ctype = ::std::os::raw::c_uint; +/// Document field with three slashes +pub const B_VAR_A: B_ctype = 0; +/// Document field with preceding star +pub const B_VAR_B: B_ctype = 1; +/// Document field with preceding exclamation +pub const B_VAR_C: B_ctype = 2; +///< Document field with following star +pub const B_VAR_D: B_ctype = 3; +///< Document field with following exclamation +pub const B_VAR_E: B_ctype = 4; +/** Document field with preceding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ +pub const B_VAR_F: B_ctype = 5; #[repr(u32)] /// Document enum #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index b728dfc898..40fb1a8a63 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -6,6 +6,9 @@ pub struct foo { } pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; +pub type foo__bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const foo__bindgen_ty_1_FOO_A: foo__bindgen_ty_1_ctype = 0; +pub const foo__bindgen_ty_1_FOO_B: foo__bindgen_ty_1_ctype = 1; #[repr(u32)] #[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum foo__bindgen_ty_1 { @@ -27,6 +30,9 @@ impl Default for foo { } } } +pub type Foo_ctype = ::std::os::raw::c_uint; +pub const Foo_Bar: Foo_ctype = 0; +pub const Foo_Qux: Foo_ctype = 1; #[repr(u32)] #[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { @@ -38,6 +44,9 @@ pub mod Neg { pub const MinusOne: Type = -1; pub const One: Type = 1; } +pub type NoDebug_ctype = ::std::os::raw::c_uint; +pub const NoDebug_NoDebug1: NoDebug_ctype = 0; +pub const NoDebug_NoDebug2: NoDebug_ctype = 1; #[repr(u32)] ///
#[derive(Copy, Clone, Hash, PartialEq, Eq)] @@ -45,6 +54,9 @@ pub enum NoDebug { NoDebug1 = 0, NoDebug2 = 1, } +pub type Debug_ctype = ::std::os::raw::c_uint; +pub const Debug_Debug1: Debug_ctype = 0; +pub const Debug_Debug2: Debug_ctype = 1; #[repr(u32)] ///
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)] diff --git a/bindgen-tests/tests/expectations/tests/enum-undefault.rs b/bindgen-tests/tests/expectations/tests/enum-undefault.rs index 01a7aa3cea..953a13790f 100644 --- a/bindgen-tests/tests/expectations/tests/enum-undefault.rs +++ b/bindgen-tests/tests/expectations/tests/enum-undefault.rs @@ -1,4 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Foo_ctype = ::std::os::raw::c_uint; +pub const Foo_Bar: Foo_ctype = 0; +pub const Foo_Qux: Foo_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_alias.rs b/bindgen-tests/tests/expectations/tests/enum_alias.rs index 0d29768837..ba516dec67 100644 --- a/bindgen-tests/tests/expectations/tests/enum_alias.rs +++ b/bindgen-tests/tests/expectations/tests/enum_alias.rs @@ -1,4 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Bar_ctype = u8; +pub const Bar_VAL: Bar_ctype = 0; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index 18e1ad8e36..736f633c67 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -1,6 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const _bindgen_ty_1_match_: _bindgen_ty_1_ctype = 0; +pub const _bindgen_ty_1_whatever_else: _bindgen_ty_1_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/enum_dupe.rs b/bindgen-tests/tests/expectations/tests/enum_dupe.rs index 3ee4c68cbd..8c02f30ec5 100644 --- a/bindgen-tests/tests/expectations/tests/enum_dupe.rs +++ b/bindgen-tests/tests/expectations/tests/enum_dupe.rs @@ -2,6 +2,8 @@ impl Foo { pub const Dupe: Foo = Foo::Bar; } +pub type Foo_ctype = ::std::os::raw::c_uint; +pub const Foo_Bar: Foo_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs index 1f3dd36f96..979f8b45eb 100644 --- a/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs +++ b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs @@ -1,43 +1,62 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Foo_ctype = ::std::os::raw::c_uchar; +pub const Foo_Bar: Foo_ctype = 0; +pub const Foo_Qux: Foo_ctype = 1; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, } +pub type Neg_ctype = ::std::os::raw::c_schar; +pub const Neg_MinusOne: Neg_ctype = -1; +pub const Neg_One: Neg_ctype = 1; #[repr(i8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Neg { MinusOne = -1, One = 1, } +pub type Bigger_ctype = ::std::os::raw::c_ushort; +pub const Bigger_Much: Bigger_ctype = 255; +pub const Bigger_Larger: Bigger_ctype = 256; #[repr(u16)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bigger { Much = 255, Larger = 256, } +pub type MuchLong_ctype = ::std::os::raw::c_long; +pub const MuchLong_MuchLow: MuchLong_ctype = -4294967296; #[repr(i64)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MuchLong { MuchLow = -4294967296, } +pub type MuchLongLong_ctype = ::std::os::raw::c_longlong; +pub const MuchLongLong_I64_MIN: MuchLongLong_ctype = -9223372036854775808; #[repr(i64)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MuchLongLong { I64_MIN = -9223372036854775808, } +pub type MuchULongLong_ctype = ::std::os::raw::c_ulonglong; +pub const MuchULongLong_MuchHigh: MuchULongLong_ctype = 4294967296; #[repr(u64)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MuchULongLong { MuchHigh = 4294967296, } +pub type BoolEnumsAreFun_ctype = bool; +pub const BoolEnumsAreFun_Value: BoolEnumsAreFun_ctype = 1 as BoolEnumsAreFun_ctype; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum BoolEnumsAreFun { Value = 1, } pub type MyType = bool; +pub type BoolEnumsAreFun2_ctype = MyType; +pub const BoolEnumsAreFun2_Value2: BoolEnumsAreFun2_ctype = 1 as BoolEnumsAreFun2_ctype; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum BoolEnumsAreFun2 { @@ -45,6 +64,9 @@ pub enum BoolEnumsAreFun2 { } pub const AnonymousVariantOne: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantOne; pub const AnonymousVariantTwo: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantTwo; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uchar; +pub const _bindgen_ty_1_AnonymousVariantOne: _bindgen_ty_1_ctype = 0; +pub const _bindgen_ty_1_AnonymousVariantTwo: _bindgen_ty_1_ctype = 1; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs index b71923e10f..7ee152b075 100644 --- a/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -8,6 +8,8 @@ pub type std_fbstring_core_category_type = u8; impl std_fbstring_core_Category { pub const Bar: std_fbstring_core_Category = std_fbstring_core_Category::Foo; } +pub type std_fbstring_core_Category_ctype = std_fbstring_core_category_type; +pub const std_fbstring_core_Category_Foo: std_fbstring_core_Category_ctype = 0; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum std_fbstring_core_Category { diff --git a/bindgen-tests/tests/expectations/tests/enum_negative.rs b/bindgen-tests/tests/expectations/tests/enum_negative.rs index f946e0f044..2a204f019a 100644 --- a/bindgen-tests/tests/expectations/tests/enum_negative.rs +++ b/bindgen-tests/tests/expectations/tests/enum_negative.rs @@ -1,4 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Foo_ctype = ::std::os::raw::c_int; +pub const Foo_Bar: Foo_ctype = -2; +pub const Foo_Qux: Foo_ctype = 1; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_packed.rs b/bindgen-tests/tests/expectations/tests/enum_packed.rs index d4ec2192d1..24b9cc5890 100644 --- a/bindgen-tests/tests/expectations/tests/enum_packed.rs +++ b/bindgen-tests/tests/expectations/tests/enum_packed.rs @@ -1,16 +1,25 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Foo_ctype = ::std::os::raw::c_uchar; +pub const Foo_Bar: Foo_ctype = 0; +pub const Foo_Qux: Foo_ctype = 1; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, } +pub type Neg_ctype = ::std::os::raw::c_schar; +pub const Neg_MinusOne: Neg_ctype = -1; +pub const Neg_One: Neg_ctype = 1; #[repr(i8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Neg { MinusOne = -1, One = 1, } +pub type Bigger_ctype = ::std::os::raw::c_ushort; +pub const Bigger_Much: Bigger_ctype = 255; +pub const Bigger_Larger: Bigger_ctype = 256; #[repr(u16)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bigger { diff --git a/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs index 9949b39aae..de6c4d7cb9 100644 --- a/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs +++ b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs @@ -1,4 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type CSSPseudoClassType_ctype = ::std::os::raw::c_int; +pub const CSSPseudoClassType_empty: CSSPseudoClassType_ctype = 0; +pub const CSSPseudoClassType_link: CSSPseudoClassType_ctype = 1; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum CSSPseudoClassType { diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs index 308bb069e0..aa304e6197 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs @@ -1,4 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type baz_ctype = i32; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum baz { diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs index f41d6e90ec..f86e28571b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs @@ -2,6 +2,9 @@ impl MyDupeEnum { pub const A_alias: MyDupeEnum = MyDupeEnum::A; } +pub type MyDupeEnum_ctype = ::std::os::raw::c_uint; +pub const MyDupeEnum_A: MyDupeEnum_ctype = 0; +pub const MyDupeEnum_B: MyDupeEnum_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MyDupeEnum { @@ -11,6 +14,9 @@ pub enum MyDupeEnum { impl MyOtherDupeEnum { pub const C_alias: MyOtherDupeEnum = MyOtherDupeEnum::C; } +pub type MyOtherDupeEnum_ctype = ::std::os::raw::c_uint; +pub const MyOtherDupeEnum_C: MyOtherDupeEnum_ctype = 0; +pub const MyOtherDupeEnum_D: MyOtherDupeEnum_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MyOtherDupeEnum { diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs index 60882da2d5..048f1cd030 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -13,6 +13,9 @@ pub mod Bar { #[repr(transparent)] #[derive(Debug, Copy, Clone)] pub struct BarAlias(pub Bar::Type); +pub type Qux_ctype = ::std::os::raw::c_uint; +pub const Qux_E: Qux_ctype = 0; +pub const Qux_F: Qux_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Qux { diff --git a/bindgen-tests/tests/expectations/tests/issue-1554.rs b/bindgen-tests/tests/expectations/tests/issue-1554.rs index 7b1a2cd410..3410e69a78 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1554.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1554.rs @@ -1,6 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(non_exhaustive)] +pub type Planet_ctype = ::std::os::raw::c_uint; +pub const Planet_earth: Planet_ctype = 0; +pub const Planet_mars: Planet_ctype = 1; #[repr(u32)] #[non_exhaustive] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/issue-2646.rs b/bindgen-tests/tests/expectations/tests/issue-2646.rs new file mode 100644 index 0000000000..fcb74a7146 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2646.rs @@ -0,0 +1,101 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Plain_ctype = ::std::os::raw::c_uint; +pub const Plain_Plain1: Plain_ctype = 0; +pub const Plain_Plain2: Plain_ctype = 1; +pub const Plain_Plain3: Plain_ctype = 2; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Plain { + Plain1 = 0, + Plain2 = 1, + Plain3 = 2, +} +pub type TryFromRaw_ctype = ::std::os::raw::c_int; +pub const TryFromRaw_TFR1: TryFromRaw_ctype = -1; +pub const TryFromRaw_TFR2: TryFromRaw_ctype = 5; +pub const TryFromRaw_TFR3: TryFromRaw_ctype = 6; +#[repr(i32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum TryFromRaw { + TFR1 = -1, + TFR2 = 5, + TFR3 = 6, +} +pub struct TryFromRawError(TryFromRaw_ctype); +impl TryFromRawError { + #[must_use] + pub fn value(&self) -> TryFromRaw_ctype { + self.0 + } +} +impl std::convert::TryFrom for TryFromRaw { + type Error = TryFromRawError; + fn try_from(v: TryFromRaw_ctype) -> Result { + match v { + -1 => TryFromRaw::TFR1, + 5 => TryFromRaw::TFR2, + 6 => TryFromRaw::TFR3, + _ => TryFromRawError(v), + } + } +} +pub type FromRawUnchecked_ctype = ::std::os::raw::c_uint; +pub const FromRawUnchecked_FRU1: FromRawUnchecked_ctype = 6; +pub const FromRawUnchecked_FRU2: FromRawUnchecked_ctype = 10; +pub const FromRawUnchecked_FRU3: FromRawUnchecked_ctype = 11; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum FromRawUnchecked { + FRU1 = 6, + FRU2 = 10, + FRU3 = 11, +} +impl FromRawUnchecked { + const unsafe fn from_ctype_unchecked(v: FromRawUnchecked_ctype) -> Self { + std::mem::transmute(v) + } +} +impl Both { + pub const Both3: Both = Both::Both1; +} +pub type Both_ctype = ::std::os::raw::c_int; +pub const Both_Both1: Both_ctype = 0; +pub const Both_Both2: Both_ctype = -1; +#[repr(i32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Both { + Both1 = 0, + Both2 = -1, +} +pub struct BothError(Both_ctype); +impl BothError { + #[must_use] + pub fn value(&self) -> Both_ctype { + self.0 + } +} +impl std::convert::TryFrom for Both { + type Error = BothError; + fn try_from(v: Both_ctype) -> Result { + match v { + 0 => Both::Both1, + -1 => Both::Both2, + _ => BothError(v), + } + } +} +impl Both { + const unsafe fn from_ctype_unchecked(v: Both_ctype) -> Self { + std::mem::transmute(v) + } +} +pub type NonExhaustive_ctype = ::std::os::raw::c_uint; +pub const NonExhaustive_Ex1: NonExhaustive_ctype = 0; +pub const NonExhaustive_Ex2: NonExhaustive_ctype = 1; +#[repr(u32)] +#[non_exhaustive] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum NonExhaustive { + Ex1 = 0, + Ex2 = 1, +} diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index 80b8cbe8b6..b8e5b6917f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -67,6 +67,19 @@ pub mod root { } } } + pub type n_ctype = ::std::os::raw::c_uint; + pub const n_o: n_ctype = 0; + pub const n_p: n_ctype = 1; + pub const n_q: n_ctype = 2; + pub const n_r: n_ctype = 3; + pub const n_s: n_ctype = 4; + pub const n_t: n_ctype = 5; + pub const n_b: n_ctype = 6; + pub const n_ae: n_ctype = 7; + pub const n_e: n_ctype = 8; + pub const n_ag: n_ctype = 9; + pub const n_ah: n_ctype = 10; + pub const n_ai: n_ctype = 11; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum n { diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index e52aa25a13..1307bd6267 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -27,6 +27,7 @@ pub mod root { } } } + pub type JSWhyMagic_ctype = ::std::os::raw::c_uint; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index d2e4ea5375..0c66679e2a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -67,6 +67,8 @@ impl Default for basic_string___long { } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; +pub type basic_string__bindgen_ty_1_ctype = i32; +pub const basic_string__bindgen_ty_1___min_cap: basic_string__bindgen_ty_1_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { @@ -117,6 +119,8 @@ impl Default for basic_string___ulx { } } pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; +pub type basic_string__bindgen_ty_2_ctype = i32; +pub const basic_string__bindgen_ty_2___n_words: basic_string__bindgen_ty_2_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index ff0c93428b..e46cb9ce25 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -67,6 +67,8 @@ impl Default for basic_string___long { } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; +pub type basic_string__bindgen_ty_1_ctype = i32; +pub const basic_string__bindgen_ty_1___min_cap: basic_string__bindgen_ty_1_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { @@ -102,6 +104,8 @@ pub struct basic_string___ulx { pub bindgen_union_field: [u8; 0usize], } pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; +pub type basic_string__bindgen_ty_2_ctype = i32; +pub const basic_string__bindgen_ty_2___n_words: basic_string__bindgen_ty_2_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 567325b82d..4b9b789b3f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -1,6 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +pub const _bindgen_ty_1_ENUM_VARIANT_1: _bindgen_ty_1_ctype = 0; +pub const _bindgen_ty_1_ENUM_VARIANT_2: _bindgen_ty_1_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 0a0d05f9f9..0afcb6bcf6 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -21,6 +21,7 @@ pub mod root { ["Alignment of Type"][::std::mem::align_of::() - 1usize]; }; } + pub type a_ctype = ::std::os::raw::c_uint; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum a { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index e7cb9af39e..5b53bc54bc 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -86,6 +86,18 @@ where pub const JSVAL_TAG_SHIFT: u32 = 47; pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; pub const JSVAL_TAG_MASK: i64 = -140737488355328; +pub type JSValueType_ctype = ::std::os::raw::c_uchar; +pub const JSValueType_JSVAL_TYPE_DOUBLE: JSValueType_ctype = 0; +pub const JSValueType_JSVAL_TYPE_INT32: JSValueType_ctype = 1; +pub const JSValueType_JSVAL_TYPE_UNDEFINED: JSValueType_ctype = 2; +pub const JSValueType_JSVAL_TYPE_BOOLEAN: JSValueType_ctype = 3; +pub const JSValueType_JSVAL_TYPE_MAGIC: JSValueType_ctype = 4; +pub const JSValueType_JSVAL_TYPE_STRING: JSValueType_ctype = 5; +pub const JSValueType_JSVAL_TYPE_SYMBOL: JSValueType_ctype = 6; +pub const JSValueType_JSVAL_TYPE_NULL: JSValueType_ctype = 7; +pub const JSValueType_JSVAL_TYPE_OBJECT: JSValueType_ctype = 8; +pub const JSValueType_JSVAL_TYPE_UNKNOWN: JSValueType_ctype = 32; +pub const JSValueType_JSVAL_TYPE_MISSING: JSValueType_ctype = 33; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -101,6 +113,16 @@ pub enum JSValueType { JSVAL_TYPE_UNKNOWN = 32, JSVAL_TYPE_MISSING = 33, } +pub type JSValueTag_ctype = ::std::os::raw::c_uint; +pub const JSValueTag_JSVAL_TAG_MAX_DOUBLE: JSValueTag_ctype = 131056; +pub const JSValueTag_JSVAL_TAG_INT32: JSValueTag_ctype = 131057; +pub const JSValueTag_JSVAL_TAG_UNDEFINED: JSValueTag_ctype = 131058; +pub const JSValueTag_JSVAL_TAG_STRING: JSValueTag_ctype = 131061; +pub const JSValueTag_JSVAL_TAG_SYMBOL: JSValueTag_ctype = 131062; +pub const JSValueTag_JSVAL_TAG_BOOLEAN: JSValueTag_ctype = 131059; +pub const JSValueTag_JSVAL_TAG_MAGIC: JSValueTag_ctype = 131060; +pub const JSValueTag_JSVAL_TAG_NULL: JSValueTag_ctype = 131063; +pub const JSValueTag_JSVAL_TAG_OBJECT: JSValueTag_ctype = 131064; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueTag { @@ -114,6 +136,16 @@ pub enum JSValueTag { JSVAL_TAG_NULL = 131063, JSVAL_TAG_OBJECT = 131064, } +pub type JSValueShiftedTag_ctype = ::std::os::raw::c_ulong; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_MAX_DOUBLE: JSValueShiftedTag_ctype = 18444492278190833663; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_INT32: JSValueShiftedTag_ctype = 18444633011384221696; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_UNDEFINED: JSValueShiftedTag_ctype = 18444773748872577024; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_STRING: JSValueShiftedTag_ctype = 18445195961337643008; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_SYMBOL: JSValueShiftedTag_ctype = 18445336698825998336; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_BOOLEAN: JSValueShiftedTag_ctype = 18444914486360932352; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_MAGIC: JSValueShiftedTag_ctype = 18445055223849287680; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_NULL: JSValueShiftedTag_ctype = 18445477436314353664; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_OBJECT: JSValueShiftedTag_ctype = 18445618173802708992; #[repr(u64)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueShiftedTag { @@ -127,6 +159,45 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } +pub type JSWhyMagic_ctype = ::std::os::raw::c_uint; +/// a hole in a native object's elements +pub const JSWhyMagic_JS_ELEMENTS_HOLE: JSWhyMagic_ctype = 0; +/// there is not a pending iterator value +pub const JSWhyMagic_JS_NO_ITER_VALUE: JSWhyMagic_ctype = 1; +/// exception value thrown when closing a generator +pub const JSWhyMagic_JS_GENERATOR_CLOSING: JSWhyMagic_ctype = 2; +/// compiler sentinel value +pub const JSWhyMagic_JS_NO_CONSTANT: JSWhyMagic_ctype = 3; +/// used in debug builds to catch tracing errors +pub const JSWhyMagic_JS_THIS_POISON: JSWhyMagic_ctype = 4; +/// used in debug builds to catch tracing errors +pub const JSWhyMagic_JS_ARG_POISON: JSWhyMagic_ctype = 5; +/// an empty subnode in the AST serializer +pub const JSWhyMagic_JS_SERIALIZE_NO_NODE: JSWhyMagic_ctype = 6; +/// lazy arguments value on the stack +pub const JSWhyMagic_JS_LAZY_ARGUMENTS: JSWhyMagic_ctype = 7; +/// optimized-away 'arguments' value +pub const JSWhyMagic_JS_OPTIMIZED_ARGUMENTS: JSWhyMagic_ctype = 8; +/// magic value passed to natives to indicate construction +pub const JSWhyMagic_JS_IS_CONSTRUCTING: JSWhyMagic_ctype = 9; +/// arguments.callee has been overwritten +pub const JSWhyMagic_JS_OVERWRITTEN_CALLEE: JSWhyMagic_ctype = 10; +/// value of static block object slot +pub const JSWhyMagic_JS_BLOCK_NEEDS_CLONE: JSWhyMagic_ctype = 11; +/// see class js::HashableValue +pub const JSWhyMagic_JS_HASH_KEY_EMPTY: JSWhyMagic_ctype = 12; +/// error while running Ion code +pub const JSWhyMagic_JS_ION_ERROR: JSWhyMagic_ctype = 13; +/// missing recover instruction result +pub const JSWhyMagic_JS_ION_BAILOUT: JSWhyMagic_ctype = 14; +/// optimized out slot +pub const JSWhyMagic_JS_OPTIMIZED_OUT: JSWhyMagic_ctype = 15; +/// uninitialized lexical bindings that produce ReferenceError on touch. +pub const JSWhyMagic_JS_UNINITIALIZED_LEXICAL: JSWhyMagic_ctype = 16; +/// for local use +pub const JSWhyMagic_JS_GENERIC_MAGIC: JSWhyMagic_ctype = 17; +/// for local use +pub const JSWhyMagic_JS_WHY_MAGIC_COUNT: JSWhyMagic_ctype = 18; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 7ae53bc40f..af2a6d3277 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -129,6 +129,18 @@ impl ::std::cmp::Eq for __BindgenUnionField {} pub const JSVAL_TAG_SHIFT: u32 = 47; pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; pub const JSVAL_TAG_MASK: i64 = -140737488355328; +pub type JSValueType_ctype = ::std::os::raw::c_uchar; +pub const JSValueType_JSVAL_TYPE_DOUBLE: JSValueType_ctype = 0; +pub const JSValueType_JSVAL_TYPE_INT32: JSValueType_ctype = 1; +pub const JSValueType_JSVAL_TYPE_UNDEFINED: JSValueType_ctype = 2; +pub const JSValueType_JSVAL_TYPE_BOOLEAN: JSValueType_ctype = 3; +pub const JSValueType_JSVAL_TYPE_MAGIC: JSValueType_ctype = 4; +pub const JSValueType_JSVAL_TYPE_STRING: JSValueType_ctype = 5; +pub const JSValueType_JSVAL_TYPE_SYMBOL: JSValueType_ctype = 6; +pub const JSValueType_JSVAL_TYPE_NULL: JSValueType_ctype = 7; +pub const JSValueType_JSVAL_TYPE_OBJECT: JSValueType_ctype = 8; +pub const JSValueType_JSVAL_TYPE_UNKNOWN: JSValueType_ctype = 32; +pub const JSValueType_JSVAL_TYPE_MISSING: JSValueType_ctype = 33; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -144,6 +156,16 @@ pub enum JSValueType { JSVAL_TYPE_UNKNOWN = 32, JSVAL_TYPE_MISSING = 33, } +pub type JSValueTag_ctype = ::std::os::raw::c_uint; +pub const JSValueTag_JSVAL_TAG_MAX_DOUBLE: JSValueTag_ctype = 131056; +pub const JSValueTag_JSVAL_TAG_INT32: JSValueTag_ctype = 131057; +pub const JSValueTag_JSVAL_TAG_UNDEFINED: JSValueTag_ctype = 131058; +pub const JSValueTag_JSVAL_TAG_STRING: JSValueTag_ctype = 131061; +pub const JSValueTag_JSVAL_TAG_SYMBOL: JSValueTag_ctype = 131062; +pub const JSValueTag_JSVAL_TAG_BOOLEAN: JSValueTag_ctype = 131059; +pub const JSValueTag_JSVAL_TAG_MAGIC: JSValueTag_ctype = 131060; +pub const JSValueTag_JSVAL_TAG_NULL: JSValueTag_ctype = 131063; +pub const JSValueTag_JSVAL_TAG_OBJECT: JSValueTag_ctype = 131064; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueTag { @@ -157,6 +179,16 @@ pub enum JSValueTag { JSVAL_TAG_NULL = 131063, JSVAL_TAG_OBJECT = 131064, } +pub type JSValueShiftedTag_ctype = ::std::os::raw::c_ulong; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_MAX_DOUBLE: JSValueShiftedTag_ctype = 18444492278190833663; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_INT32: JSValueShiftedTag_ctype = 18444633011384221696; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_UNDEFINED: JSValueShiftedTag_ctype = 18444773748872577024; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_STRING: JSValueShiftedTag_ctype = 18445195961337643008; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_SYMBOL: JSValueShiftedTag_ctype = 18445336698825998336; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_BOOLEAN: JSValueShiftedTag_ctype = 18444914486360932352; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_MAGIC: JSValueShiftedTag_ctype = 18445055223849287680; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_NULL: JSValueShiftedTag_ctype = 18445477436314353664; +pub const JSValueShiftedTag_JSVAL_SHIFTED_TAG_OBJECT: JSValueShiftedTag_ctype = 18445618173802708992; #[repr(u64)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueShiftedTag { @@ -170,6 +202,45 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } +pub type JSWhyMagic_ctype = ::std::os::raw::c_uint; +/// a hole in a native object's elements +pub const JSWhyMagic_JS_ELEMENTS_HOLE: JSWhyMagic_ctype = 0; +/// there is not a pending iterator value +pub const JSWhyMagic_JS_NO_ITER_VALUE: JSWhyMagic_ctype = 1; +/// exception value thrown when closing a generator +pub const JSWhyMagic_JS_GENERATOR_CLOSING: JSWhyMagic_ctype = 2; +/// compiler sentinel value +pub const JSWhyMagic_JS_NO_CONSTANT: JSWhyMagic_ctype = 3; +/// used in debug builds to catch tracing errors +pub const JSWhyMagic_JS_THIS_POISON: JSWhyMagic_ctype = 4; +/// used in debug builds to catch tracing errors +pub const JSWhyMagic_JS_ARG_POISON: JSWhyMagic_ctype = 5; +/// an empty subnode in the AST serializer +pub const JSWhyMagic_JS_SERIALIZE_NO_NODE: JSWhyMagic_ctype = 6; +/// lazy arguments value on the stack +pub const JSWhyMagic_JS_LAZY_ARGUMENTS: JSWhyMagic_ctype = 7; +/// optimized-away 'arguments' value +pub const JSWhyMagic_JS_OPTIMIZED_ARGUMENTS: JSWhyMagic_ctype = 8; +/// magic value passed to natives to indicate construction +pub const JSWhyMagic_JS_IS_CONSTRUCTING: JSWhyMagic_ctype = 9; +/// arguments.callee has been overwritten +pub const JSWhyMagic_JS_OVERWRITTEN_CALLEE: JSWhyMagic_ctype = 10; +/// value of static block object slot +pub const JSWhyMagic_JS_BLOCK_NEEDS_CLONE: JSWhyMagic_ctype = 11; +/// see class js::HashableValue +pub const JSWhyMagic_JS_HASH_KEY_EMPTY: JSWhyMagic_ctype = 12; +/// error while running Ion code +pub const JSWhyMagic_JS_ION_ERROR: JSWhyMagic_ctype = 13; +/// missing recover instruction result +pub const JSWhyMagic_JS_ION_BAILOUT: JSWhyMagic_ctype = 14; +/// optimized out slot +pub const JSWhyMagic_JS_OPTIMIZED_OUT: JSWhyMagic_ctype = 15; +/// uninitialized lexical bindings that produce ReferenceError on touch. +pub const JSWhyMagic_JS_UNINITIALIZED_LEXICAL: JSWhyMagic_ctype = 16; +/// for local use +pub const JSWhyMagic_JS_GENERIC_MAGIC: JSWhyMagic_ctype = 17; +/// for local use +pub const JSWhyMagic_JS_WHY_MAGIC_COUNT: JSWhyMagic_ctype = 18; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs index d6ce2883d7..d6aa5e125d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs @@ -5,6 +5,14 @@ pub const IP_LAST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_LAST_FRAG_IDX; pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +///< index of last fragment +pub const _bindgen_ty_1_IP_LAST_FRAG_IDX: _bindgen_ty_1_ctype = 0; +///< index of first fragment +pub const _bindgen_ty_1_IP_FIRST_FRAG_IDX: _bindgen_ty_1_ctype = 1; +///< minimum number of fragments +pub const _bindgen_ty_1_IP_MIN_FRAG_NUM: _bindgen_ty_1_ctype = 2; +pub const _bindgen_ty_1_IP_MAX_FRAG_NUM: _bindgen_ty_1_ctype = 4; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs index fb7b3bf584..ad2012bcf5 100644 --- a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs +++ b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs @@ -104,6 +104,15 @@ const _: () = { "Offset of field: cmdline_token_ops::get_help", ][::std::mem::offset_of!(cmdline_token_ops, get_help) - 24usize]; }; +pub type cmdline_numtype_ctype = ::std::os::raw::c_uint; +pub const cmdline_numtype_UINT8: cmdline_numtype_ctype = 0; +pub const cmdline_numtype_UINT16: cmdline_numtype_ctype = 1; +pub const cmdline_numtype_UINT32: cmdline_numtype_ctype = 2; +pub const cmdline_numtype_UINT64: cmdline_numtype_ctype = 3; +pub const cmdline_numtype_INT8: cmdline_numtype_ctype = 4; +pub const cmdline_numtype_INT16: cmdline_numtype_ctype = 5; +pub const cmdline_numtype_INT32: cmdline_numtype_ctype = 6; +pub const cmdline_numtype_INT64: cmdline_numtype_ctype = 7; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum cmdline_numtype { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 9b98bac376..e6e4c84a9d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -115,6 +115,23 @@ pub const RTE_ETH_FLOW_VXLAN: u32 = 19; pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; +pub type rte_eth_rx_mq_mode_ctype = ::std::os::raw::c_uint; +/// None of DCB,RSS or VMDQ mode +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_NONE: rte_eth_rx_mq_mode_ctype = 0; +/// For RX side, only RSS is on +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_RSS: rte_eth_rx_mq_mode_ctype = 1; +/// For RX side,only DCB is on. +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_DCB: rte_eth_rx_mq_mode_ctype = 2; +/// Both DCB and RSS enable +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_DCB_RSS: rte_eth_rx_mq_mode_ctype = 3; +/// Only VMDQ, no RSS nor DCB +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_ONLY: rte_eth_rx_mq_mode_ctype = 4; +/// RSS mode with VMDQ +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_RSS: rte_eth_rx_mq_mode_ctype = 5; +/// Use VMDQ+DCB to route traffic to queues +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_DCB: rte_eth_rx_mq_mode_ctype = 6; +/// Enable both VMDQ and DCB in VMDq +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_DCB_RSS: rte_eth_rx_mq_mode_ctype = 7; #[repr(u32)] /** A set of values to identify what method is to be used to route packets to multiple queues.*/ @@ -400,6 +417,15 @@ impl rte_eth_rxmode { __bindgen_bitfield_unit } } +pub type rte_eth_tx_mq_mode_ctype = ::std::os::raw::c_uint; +///< It is in neither DCB nor VT mode. +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_NONE: rte_eth_tx_mq_mode_ctype = 0; +///< For TX side,only DCB is on. +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_DCB: rte_eth_tx_mq_mode_ctype = 1; +///< For TX side,both DCB and VT is on. +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_VMDQ_DCB: rte_eth_tx_mq_mode_ctype = 2; +///< Only VT on, no DCB +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_VMDQ_ONLY: rte_eth_tx_mq_mode_ctype = 3; #[repr(u32)] /** A set of values to identify what method is to be used to transmit packets using multi-TCs.*/ @@ -600,6 +626,11 @@ impl Default for rte_eth_rss_conf { } } } +pub type rte_eth_nb_tcs_ctype = ::std::os::raw::c_uint; +///< 4 TCs with DCB. +pub const rte_eth_nb_tcs_ETH_4_TCS: rte_eth_nb_tcs_ctype = 4; +///< 8 TCs with DCB. +pub const rte_eth_nb_tcs_ETH_8_TCS: rte_eth_nb_tcs_ctype = 8; #[repr(u32)] /** This enum indicates the possible number of traffic classes in DCB configratioins*/ @@ -610,6 +641,15 @@ pub enum rte_eth_nb_tcs { ///< 8 TCs with DCB. ETH_8_TCS = 8, } +pub type rte_eth_nb_pools_ctype = ::std::os::raw::c_uint; +///< 8 VMDq pools. +pub const rte_eth_nb_pools_ETH_8_POOLS: rte_eth_nb_pools_ctype = 8; +///< 16 VMDq pools. +pub const rte_eth_nb_pools_ETH_16_POOLS: rte_eth_nb_pools_ctype = 16; +///< 32 VMDq pools. +pub const rte_eth_nb_pools_ETH_32_POOLS: rte_eth_nb_pools_ctype = 32; +///< 64 VMDq pools. +pub const rte_eth_nb_pools_ETH_64_POOLS: rte_eth_nb_pools_ctype = 64; #[repr(u32)] /** This enum indicates the possible number of queue pools in VMDQ configurations.*/ @@ -1010,6 +1050,17 @@ impl Default for rte_eth_vmdq_rx_conf { } } } +pub type rte_fdir_mode_ctype = ::std::os::raw::c_uint; +///< Disable FDIR support. +pub const rte_fdir_mode_RTE_FDIR_MODE_NONE: rte_fdir_mode_ctype = 0; +///< Enable FDIR signature filter mode. +pub const rte_fdir_mode_RTE_FDIR_MODE_SIGNATURE: rte_fdir_mode_ctype = 1; +///< Enable FDIR perfect filter mode. +pub const rte_fdir_mode_RTE_FDIR_MODE_PERFECT: rte_fdir_mode_ctype = 2; +///< Enable FDIR filter mode - MAC VLAN. +pub const rte_fdir_mode_RTE_FDIR_MODE_PERFECT_MAC_VLAN: rte_fdir_mode_ctype = 3; +///< Enable FDIR filter mode - tunnel. +pub const rte_fdir_mode_RTE_FDIR_MODE_PERFECT_TUNNEL: rte_fdir_mode_ctype = 4; #[repr(u32)] /// Flow Director setting modes: none, signature or perfect. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -1025,6 +1076,13 @@ pub enum rte_fdir_mode { ///< Enable FDIR filter mode - tunnel. RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } +pub type rte_fdir_pballoc_type_ctype = ::std::os::raw::c_uint; +///< 64k. +pub const rte_fdir_pballoc_type_RTE_FDIR_PBALLOC_64K: rte_fdir_pballoc_type_ctype = 0; +///< 128k. +pub const rte_fdir_pballoc_type_RTE_FDIR_PBALLOC_128K: rte_fdir_pballoc_type_ctype = 1; +///< 256k. +pub const rte_fdir_pballoc_type_RTE_FDIR_PBALLOC_256K: rte_fdir_pballoc_type_ctype = 2; #[repr(u32)] /** Memory space that can be configured to store Flow Director filters in the board memory.*/ @@ -1037,6 +1095,13 @@ pub enum rte_fdir_pballoc_type { ///< 256k. RTE_FDIR_PBALLOC_256K = 2, } +pub type rte_fdir_status_mode_ctype = ::std::os::raw::c_uint; +///< Never report FDIR hash. +pub const rte_fdir_status_mode_RTE_FDIR_NO_REPORT_STATUS: rte_fdir_status_mode_ctype = 0; +///< Only report FDIR hash for matching pkts. +pub const rte_fdir_status_mode_RTE_FDIR_REPORT_STATUS: rte_fdir_status_mode_ctype = 1; +///< Always report FDIR hash. +pub const rte_fdir_status_mode_RTE_FDIR_REPORT_STATUS_ALWAYS: rte_fdir_status_mode_ctype = 2; #[repr(u32)] /// Select report mode of FDIR hash information in RX descriptors. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -1239,6 +1304,13 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", ); } +pub type rte_eth_payload_type_ctype = ::std::os::raw::c_uint; +pub const rte_eth_payload_type_RTE_ETH_PAYLOAD_UNKNOWN: rte_eth_payload_type_ctype = 0; +pub const rte_eth_payload_type_RTE_ETH_RAW_PAYLOAD: rte_eth_payload_type_ctype = 1; +pub const rte_eth_payload_type_RTE_ETH_L2_PAYLOAD: rte_eth_payload_type_ctype = 2; +pub const rte_eth_payload_type_RTE_ETH_L3_PAYLOAD: rte_eth_payload_type_ctype = 3; +pub const rte_eth_payload_type_RTE_ETH_L4_PAYLOAD: rte_eth_payload_type_ctype = 4; +pub const rte_eth_payload_type_RTE_ETH_PAYLOAD_MAX: rte_eth_payload_type_ctype = 8; #[repr(u32)] /// Payload type #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index 34688b20b3..db331f9a36 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -158,6 +158,23 @@ pub const RTE_ETH_FLOW_VXLAN: u32 = 19; pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; +pub type rte_eth_rx_mq_mode_ctype = ::std::os::raw::c_uint; +/// None of DCB,RSS or VMDQ mode +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_NONE: rte_eth_rx_mq_mode_ctype = 0; +/// For RX side, only RSS is on +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_RSS: rte_eth_rx_mq_mode_ctype = 1; +/// For RX side,only DCB is on. +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_DCB: rte_eth_rx_mq_mode_ctype = 2; +/// Both DCB and RSS enable +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_DCB_RSS: rte_eth_rx_mq_mode_ctype = 3; +/// Only VMDQ, no RSS nor DCB +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_ONLY: rte_eth_rx_mq_mode_ctype = 4; +/// RSS mode with VMDQ +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_RSS: rte_eth_rx_mq_mode_ctype = 5; +/// Use VMDQ+DCB to route traffic to queues +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_DCB: rte_eth_rx_mq_mode_ctype = 6; +/// Enable both VMDQ and DCB in VMDq +pub const rte_eth_rx_mq_mode_ETH_MQ_RX_VMDQ_DCB_RSS: rte_eth_rx_mq_mode_ctype = 7; #[repr(u32)] /** A set of values to identify what method is to be used to route packets to multiple queues.*/ @@ -448,6 +465,15 @@ impl rte_eth_rxmode { __bindgen_bitfield_unit } } +pub type rte_eth_tx_mq_mode_ctype = ::std::os::raw::c_uint; +///< It is in neither DCB nor VT mode. +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_NONE: rte_eth_tx_mq_mode_ctype = 0; +///< For TX side,only DCB is on. +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_DCB: rte_eth_tx_mq_mode_ctype = 1; +///< For TX side,both DCB and VT is on. +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_VMDQ_DCB: rte_eth_tx_mq_mode_ctype = 2; +///< Only VT on, no DCB +pub const rte_eth_tx_mq_mode_ETH_MQ_TX_VMDQ_ONLY: rte_eth_tx_mq_mode_ctype = 3; #[repr(u32)] /** A set of values to identify what method is to be used to transmit packets using multi-TCs.*/ @@ -658,6 +684,11 @@ impl Default for rte_eth_rss_conf { } } } +pub type rte_eth_nb_tcs_ctype = ::std::os::raw::c_uint; +///< 4 TCs with DCB. +pub const rte_eth_nb_tcs_ETH_4_TCS: rte_eth_nb_tcs_ctype = 4; +///< 8 TCs with DCB. +pub const rte_eth_nb_tcs_ETH_8_TCS: rte_eth_nb_tcs_ctype = 8; #[repr(u32)] /** This enum indicates the possible number of traffic classes in DCB configratioins*/ @@ -668,6 +699,15 @@ pub enum rte_eth_nb_tcs { ///< 8 TCs with DCB. ETH_8_TCS = 8, } +pub type rte_eth_nb_pools_ctype = ::std::os::raw::c_uint; +///< 8 VMDq pools. +pub const rte_eth_nb_pools_ETH_8_POOLS: rte_eth_nb_pools_ctype = 8; +///< 16 VMDq pools. +pub const rte_eth_nb_pools_ETH_16_POOLS: rte_eth_nb_pools_ctype = 16; +///< 32 VMDq pools. +pub const rte_eth_nb_pools_ETH_32_POOLS: rte_eth_nb_pools_ctype = 32; +///< 64 VMDq pools. +pub const rte_eth_nb_pools_ETH_64_POOLS: rte_eth_nb_pools_ctype = 64; #[repr(u32)] /** This enum indicates the possible number of queue pools in VMDQ configurations.*/ @@ -1108,6 +1148,17 @@ impl Default for rte_eth_vmdq_rx_conf { } } } +pub type rte_fdir_mode_ctype = ::std::os::raw::c_uint; +///< Disable FDIR support. +pub const rte_fdir_mode_RTE_FDIR_MODE_NONE: rte_fdir_mode_ctype = 0; +///< Enable FDIR signature filter mode. +pub const rte_fdir_mode_RTE_FDIR_MODE_SIGNATURE: rte_fdir_mode_ctype = 1; +///< Enable FDIR perfect filter mode. +pub const rte_fdir_mode_RTE_FDIR_MODE_PERFECT: rte_fdir_mode_ctype = 2; +///< Enable FDIR filter mode - MAC VLAN. +pub const rte_fdir_mode_RTE_FDIR_MODE_PERFECT_MAC_VLAN: rte_fdir_mode_ctype = 3; +///< Enable FDIR filter mode - tunnel. +pub const rte_fdir_mode_RTE_FDIR_MODE_PERFECT_TUNNEL: rte_fdir_mode_ctype = 4; #[repr(u32)] /// Flow Director setting modes: none, signature or perfect. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -1123,6 +1174,13 @@ pub enum rte_fdir_mode { ///< Enable FDIR filter mode - tunnel. RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } +pub type rte_fdir_pballoc_type_ctype = ::std::os::raw::c_uint; +///< 64k. +pub const rte_fdir_pballoc_type_RTE_FDIR_PBALLOC_64K: rte_fdir_pballoc_type_ctype = 0; +///< 128k. +pub const rte_fdir_pballoc_type_RTE_FDIR_PBALLOC_128K: rte_fdir_pballoc_type_ctype = 1; +///< 256k. +pub const rte_fdir_pballoc_type_RTE_FDIR_PBALLOC_256K: rte_fdir_pballoc_type_ctype = 2; #[repr(u32)] /** Memory space that can be configured to store Flow Director filters in the board memory.*/ @@ -1135,6 +1193,13 @@ pub enum rte_fdir_pballoc_type { ///< 256k. RTE_FDIR_PBALLOC_256K = 2, } +pub type rte_fdir_status_mode_ctype = ::std::os::raw::c_uint; +///< Never report FDIR hash. +pub const rte_fdir_status_mode_RTE_FDIR_NO_REPORT_STATUS: rte_fdir_status_mode_ctype = 0; +///< Only report FDIR hash for matching pkts. +pub const rte_fdir_status_mode_RTE_FDIR_REPORT_STATUS: rte_fdir_status_mode_ctype = 1; +///< Always report FDIR hash. +pub const rte_fdir_status_mode_RTE_FDIR_REPORT_STATUS_ALWAYS: rte_fdir_status_mode_ctype = 2; #[repr(u32)] /// Select report mode of FDIR hash information in RX descriptors. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -1352,6 +1417,13 @@ impl Clone for rte_eth_fdir_masks { *self } } +pub type rte_eth_payload_type_ctype = ::std::os::raw::c_uint; +pub const rte_eth_payload_type_RTE_ETH_PAYLOAD_UNKNOWN: rte_eth_payload_type_ctype = 0; +pub const rte_eth_payload_type_RTE_ETH_RAW_PAYLOAD: rte_eth_payload_type_ctype = 1; +pub const rte_eth_payload_type_RTE_ETH_L2_PAYLOAD: rte_eth_payload_type_ctype = 2; +pub const rte_eth_payload_type_RTE_ETH_L3_PAYLOAD: rte_eth_payload_type_ctype = 3; +pub const rte_eth_payload_type_RTE_ETH_L4_PAYLOAD: rte_eth_payload_type_ctype = 4; +pub const rte_eth_payload_type_RTE_ETH_PAYLOAD_MAX: rte_eth_payload_type_ctype = 8; #[repr(u32)] /// Payload type #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs index b72c221dca..6cb2a3dbde 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -35,6 +35,14 @@ pub const IP_LAST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_LAST_FRAG_IDX; pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; +pub type _bindgen_ty_1_ctype = ::std::os::raw::c_uint; +///< index of last fragment +pub const _bindgen_ty_1_IP_LAST_FRAG_IDX: _bindgen_ty_1_ctype = 0; +///< index of first fragment +pub const _bindgen_ty_1_IP_FIRST_FRAG_IDX: _bindgen_ty_1_ctype = 1; +///< minimum number of fragments +pub const _bindgen_ty_1_IP_MIN_FRAG_NUM: _bindgen_ty_1_ctype = 2; +pub const _bindgen_ty_1_IP_MAX_FRAG_NUM: _bindgen_ty_1_ctype = 4; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs index d93a62e746..b836b74a8a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs @@ -21,6 +21,8 @@ pub mod root { "Offset of field: typedef_struct::foo", ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; }; + pub type typedef_enum_ctype = ::std::os::raw::c_uint; + pub const typedef_enum_BAR: typedef_enum_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { @@ -47,6 +49,8 @@ pub mod root { }; pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; + pub type _bindgen_ty_2_ctype = ::std::os::raw::c_uint; + pub const _bindgen_ty_2_BAR: _bindgen_ty_2_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs index 3d8edcfdc1..b1a9c5e740 100644 --- a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs +++ b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs @@ -21,6 +21,8 @@ pub struct nsStyleAutoArray { pub mFirstElement: T, pub mOtherElements: nsTArray, } +pub type nsStyleAutoArray_WithSingleInitialElement_ctype = i32; +pub const nsStyleAutoArray_WithSingleInitialElement_WITH_SINGLE_INITIAL_ELEMENT: nsStyleAutoArray_WithSingleInitialElement_ctype = 0; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum nsStyleAutoArray_WithSingleInitialElement { diff --git a/bindgen-tests/tests/expectations/tests/ord-enum.rs b/bindgen-tests/tests/expectations/tests/ord-enum.rs index aa2e67ab91..9fc80e9e0d 100644 --- a/bindgen-tests/tests/expectations/tests/ord-enum.rs +++ b/bindgen-tests/tests/expectations/tests/ord-enum.rs @@ -1,4 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type A_ctype = ::std::os::raw::c_int; +pub const A_A0: A_ctype = 0; +pub const A_A1: A_ctype = 1; +pub const A_A2: A_ctype = 2; +pub const A_A3: A_ctype = -1; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum A { @@ -7,6 +12,11 @@ pub enum A { A2 = 2, A3 = -1, } +pub type B_ctype = ::std::os::raw::c_int; +pub const B_B0: B_ctype = 1; +pub const B_B1: B_ctype = 4; +pub const B_B2: B_ctype = 3; +pub const B_B3: B_ctype = -1; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum B { diff --git a/bindgen-tests/tests/expectations/tests/overflowed_enum.rs b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs index 2c67ba6903..c13c1fd8a7 100644 --- a/bindgen-tests/tests/expectations/tests/overflowed_enum.rs +++ b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs @@ -1,4 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Foo_ctype = ::std::os::raw::c_uint; +pub const Foo_BAP_ARM: Foo_ctype = 9698489; +pub const Foo_BAP_X86: Foo_ctype = 11960045; +pub const Foo_BAP_X86_64: Foo_ctype = 3128633167; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { @@ -6,6 +10,9 @@ pub enum Foo { BAP_X86 = 11960045, BAP_X86_64 = 3128633167, } +pub type Bar_ctype = ::std::os::raw::c_ushort; +pub const Bar_One: Bar_ctype = 1; +pub const Bar_Big: Bar_ctype = 2; #[repr(u16)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { diff --git a/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs index ff49d684f1..986111353e 100644 --- a/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -2,6 +2,8 @@ impl AVCodecID { pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN; } +pub type AVCodecID_ctype = ::std::os::raw::c_uint; +pub const AVCodecID_AV_CODEC_ID_FIRST_UNKNOWN: AVCodecID_ctype = 98304; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum AVCodecID { diff --git a/bindgen-tests/tests/expectations/tests/short-enums.rs b/bindgen-tests/tests/expectations/tests/short-enums.rs index 493bb5b419..d8acb6230f 100644 --- a/bindgen-tests/tests/expectations/tests/short-enums.rs +++ b/bindgen-tests/tests/expectations/tests/short-enums.rs @@ -1,14 +1,20 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type one_byte_t_ctype = ::std::os::raw::c_uchar; +pub const one_byte_t_SOME_VALUE: one_byte_t_ctype = 1; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum one_byte_t { SOME_VALUE = 1, } +pub type two_byte_t_ctype = ::std::os::raw::c_ushort; +pub const two_byte_t_SOME_OTHER_VALUE: two_byte_t_ctype = 256; #[repr(u16)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum two_byte_t { SOME_OTHER_VALUE = 256, } +pub type four_byte_t_ctype = ::std::os::raw::c_uint; +pub const four_byte_t_SOME_BIGGER_VALUE: four_byte_t_ctype = 16777216; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum four_byte_t { diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs index bc12a1bce8..e70a366885 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef.rs @@ -40,12 +40,16 @@ impl Default for _bindgen_ty_1 { } pub type struct_ptr_t = *mut _bindgen_ty_1; pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1; +pub type typedef_named_enum_ctype = ::std::os::raw::c_uint; +pub const typedef_named_enum_ENUM_HAS_NAME: typedef_named_enum_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_named_enum { ENUM_HAS_NAME = 1, } pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON; +pub type _bindgen_ty_2_ctype = ::std::os::raw::c_uint; +pub const _bindgen_ty_2_ENUM_IS_ANON: _bindgen_ty_2_ctype = 0; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 82f93dfd16..33cbdff5f4 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -21,6 +21,8 @@ pub mod root { "Offset of field: typedef_struct::foo", ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; }; + pub type typedef_enum_ctype = ::std::os::raw::c_uint; + pub const typedef_enum_BAR: typedef_enum_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { @@ -45,6 +47,8 @@ pub mod root { "Offset of field: typedef_struct::foo", ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; }; + pub type typedef_enum_ctype = ::std::os::raw::c_uint; + pub const typedef_enum_BAR: typedef_enum_ctype = 1; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index f76189eb74..078fc74807 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -83,6 +83,10 @@ where } } } +pub type nsStyleSVGOpacitySource_ctype = ::std::os::raw::c_uint; +pub const nsStyleSVGOpacitySource_eStyleSVGOpacitySource_Normal: nsStyleSVGOpacitySource_ctype = 0; +pub const nsStyleSVGOpacitySource_eStyleSVGOpacitySource_ContextFillOpacity: nsStyleSVGOpacitySource_ctype = 1; +pub const nsStyleSVGOpacitySource_eStyleSVGOpacitySource_ContextStrokeOpacity: nsStyleSVGOpacitySource_ctype = 2; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum nsStyleSVGOpacitySource { diff --git a/bindgen-tests/tests/headers/issue-2646.h b/bindgen-tests/tests/headers/issue-2646.h new file mode 100644 index 0000000000..63068780eb --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2646.h @@ -0,0 +1,30 @@ +// bindgen-flags: --rustified-enum 'Plain.*' --rustified-enum 'TryFromRaw.*=try_from_raw' --rustified-enum='FromRawUnchecked.*=from_raw_unchecked' --rustified-enum='Both.*=try_from_raw,from_raw_unchecked' --rustified-enum 'NonExhaustive.*=non_exhaustive' + +enum Plain { + Plain1, + Plain2, + Plain3 +}; + +enum TryFromRaw { + TFR1 = -1, + TFR2 = 5, + TFR3 +}; + +enum FromRawUnchecked { + FRU1 = 6, + FRU2 = 10, + FRU3 = 11, +}; + +enum Both { + Both1, + Both2 = -1, + Both3, +}; + +enum NonExhaustive { + Ex1, + Ex2, +}; diff --git a/bindgen/.lib.rs.swp b/bindgen/.lib.rs.swp new file mode 100644 index 0000000000000000000000000000000000000000..87d73e4f1ae305130fc1012ebf14a6821be5adbc GIT binary patch literal 81920 zcmeI52b^42eeVZi0t9S~0f!d28r#yWy*nzdj0(uBl`JevLc5X;vY4Hnxw|`Pc4j?A zyK6}#v?RczJxXXH^pX(3p(GGU;5{$|Odufy^5_l$LLjD>ga_~YJLQ%sD;dn=m6?xz znw@*kJ>`GSJ?H%Enb~k?_cg)8@*6XJ&dy{WdG^h-+rIJ0>G5~mE%UgUQfH=CZQrPS zt9)j|N~2j?C4sy3_$b5mlZ{TZ9IkJ6TJ5o!YP~WS*4O**T6HGhY@Is0VTvIIh7>qm z3Uu1DV^^G+xp>pY4SM9f?3&;{=NvrUr-$i=6c|!qNP!^*h7=f5U`T->1%?zDQsDmq z3bYr`$^16$xU*}^gWdO?y1vhFzvtceL%Qyt>3*MZ-%shff0p}w$X|B__;T*$t}nXp zYrF3My1Rb0`~G0p{kyp9zv;g3;~M1izni;0>Apw0?%&m2_w7H~b^kZq{i6GRVb}e; zyX(H4KkB-FPj~+@?)xskX8-W@yNA2(=`h`OAJL5Y9ChFIuKV|P*BkEppStd!b@9nzpvdfIR`$0&q`o8%+JD z!Kc9cz>C3u0ZZT@co=v9_&&mgFN2SQKLu|Db+84T4ekZLih$vD;I*I*7Qi?Nz>g7b zd;+`~{3&=NSOHVu9Pnd!?c2bgffs>ifvdoJZ~=HIxF5I=I0yVXcn|!02RsU_1!sWI z!NmVHcpg{+dqE!D349iL#hby?!BfDKz!Sj&xC~qh;!nV5{rdI6fw0|a)>}cl*$IQ{ zY%trYm)q3_S6cIpPOTEmgaM`Rf=l;bcbH+5h!d zndjTVj)}>s0|&>a_8piEwgwx6En9+1H)nKT9~FM>eAu23n?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ib>e-nHIJRRsPz)Qew@bSM5#=#o!5b#?-vHbrBJp5mSw}9URC&3ap2JQpy z0sai0{rNz8{}J$Da4xtnxDWU?y!t-^@$~No?*i`xPXUhx8^QPB-M_)*_C$Uc9dfF~Zawj`EvotxYDr47j-eKKG2WZEo-(;AF$};cr z<}k3Pxf9DLSoFPd!KVtuHUe`gOTi8tg|7_pNu=j6-8 zKTh6G+Bqe!kBzCD$E-NQ-O&0IcP7iwVM8lj?(Gq7d+j8>(%sL|#zKV7N7Rg{o$Dfg zVo6P;7NK(4G_~WcR}|qr)kb??b@tVxrX~tY6t>;5Ve8jVF`NU(4BcU)`HmfP$K+%rU@_*!{CpT(0%Y6U|QjK#c#yvq09(vZR$ zR-U4UCc252A?gfcZ5zj#EF{&mV$gBXKfVMBZ9C%DOyYHvwDzWOHw`inRtW=t>YUZi zjM}WvDvf5l-l)2RO`X)FFLk1zq@(76LLmFKWF1wG25e$6kQA4VIs#mO)A;6E{!cd< z8rbd|gEiOepi`$StfDv$fJjs^lkFqY?Vdj3Gxpz+o4HBoP1>3v>xK1!vyr=6>o?0!Isqj}hy>Ro zKL^DV$sUAV>Z+p~)6+0cHYR4U-^8nAcQhYL=#PScGx^LZNrrPWYJ=HMlN(JQvJ9j+ zs;rH@dAO&5zU?FET;E}3e+`Wnh?@I56cjI?H;2 z_GUMz5zd1rR(`73Hl=gM&~#vD4h6AfoRtw#`{1w02TTOw zvdF@t#!^=AFeRz7rovkJjer>|6sI4v;rlwR(j2WNoHQ{YRd&hFC|%38v1v0oZMR~I zcyZBW5E@HI6BE) -> fmt::Result { let s = match self { Self::Rust { - non_exhaustive: false, - } => "rust", - Self::Rust { - non_exhaustive: true, - } => "rust_non_exhaustive", + non_exhaustive, + safe_conversion, + unsafe_conversion, + .. + } => match (non_exhaustive, safe_conversion, unsafe_conversion) { + (false, false, false) => "rust", + (false, true, true) => "rust_conversions", + (false, true, _) => "rust_safe_conversion", + (false, _, true) => "rust_unsafe_conversion", + (true, false, false) => "rust_non_exhaustive", + (true, true, true) => "rust_non_exhaustive_conversions", + (true, true, _) => "rust_non_exhaustive_safe_conversion", + (true, _, true) => "rust_non_exhaustive_unsafe_conversion", + }, Self::NewType { is_bitfield: true, .. } => "bitfield", @@ -3084,10 +3099,46 @@ impl std::str::FromStr for EnumVariation { match s { "rust" => Ok(EnumVariation::Rust { non_exhaustive: false, + safe_conversion: false, + unsafe_conversion: false, + }), + "rust_conversions" => Ok(EnumVariation::Rust { + non_exhaustive: false, + safe_conversion: true, + unsafe_conversion: true, + }), + "rust_safe_conversion" => Ok(EnumVariation::Rust { + non_exhaustive: false, + safe_conversion: true, + unsafe_conversion: false, + }), + "rust_unsafe_conversion" => Ok(EnumVariation::Rust { + non_exhaustive: false, + safe_conversion: false, + unsafe_conversion: true, }), "rust_non_exhaustive" => Ok(EnumVariation::Rust { non_exhaustive: true, + safe_conversion: false, + unsafe_conversion: false, + }), + "rust_non_exhaustive_conversions" => Ok(EnumVariation::Rust { + non_exhaustive: true, + safe_conversion: true, + unsafe_conversion: true, + }), + "rust_non_exhaustive_safe_conversion" => Ok(EnumVariation::Rust { + non_exhaustive: true, + safe_conversion: true, + unsafe_conversion: false, }), + "rust_non_exhaustive_unsafe_conversion" => { + Ok(EnumVariation::Rust { + non_exhaustive: true, + safe_conversion: false, + unsafe_conversion: true, + }) + } "bitfield" => Ok(EnumVariation::NewType { is_bitfield: true, is_global: false, @@ -3119,8 +3170,13 @@ enum EnumBuilder<'a> { Rust { attrs: Vec, ident: Ident, - tokens: proc_macro2::TokenStream, + typedef: syn::Ident, + const_tokens: Vec, + rustified_tokens: Vec, + safe_conversion_tokens: Vec, emitted_any_variants: bool, + safe_conversion: bool, + unsafe_conversion: bool, }, NewType { canonical_name: &'a str, @@ -3148,7 +3204,7 @@ impl<'a> EnumBuilder<'a> { fn new( name: &'a str, mut attrs: Vec, - repr: syn::Type, + repr: EnumRepr, enum_variation: EnumVariation, has_typedef: bool, ) -> Self { @@ -3158,29 +3214,64 @@ impl<'a> EnumBuilder<'a> { EnumVariation::NewType { is_bitfield, is_global, - } => EnumBuilder::NewType { - canonical_name: name, - tokens: quote! { - #( #attrs )* - pub struct #ident (pub #repr); - }, - is_bitfield, - is_global, - }, + } => { + let repr = match repr { + EnumRepr::Other(r) => r, + _ => panic!( + "Should never get this variant for new type enum" + ), + }; + EnumBuilder::NewType { + canonical_name: name, + tokens: quote! { + #( #attrs )* + pub struct #ident (pub #repr); + }, + is_bitfield, + is_global, + } + } - EnumVariation::Rust { .. } => { + EnumVariation::Rust { + safe_conversion, + unsafe_conversion, + .. + } => { + let (untranslated_repr, translated_repr) = match repr { + EnumRepr::Rust(un_r, t_r) => (un_r, t_r), + _ => panic!( + "Should never get this variant for rustified enum" + ), + }; + let ctype = Ident::new( + format!("{}_ctype", ident.to_string()).as_str(), + Span::call_site(), + ); // `repr` is guaranteed to be Rustified in Enum::codegen - attrs.insert(0, quote! { #[repr( #repr )] }); - let tokens = quote!(); + attrs.insert(0, quote! { #[repr( #translated_repr)] }); EnumBuilder::Rust { attrs, + const_tokens: vec![quote! { + pub type #ctype = #untranslated_repr; + }], ident, - tokens, + typedef: ctype, + rustified_tokens: vec![], + safe_conversion_tokens: vec![], emitted_any_variants: false, + safe_conversion, + unsafe_conversion, } } EnumVariation::Consts => { + let repr = match repr { + EnumRepr::Other(r) => r, + _ => { + panic!("Should never get this variant for consts enum") + } + }; + let mut variants = Vec::new(); if !has_typedef { @@ -3194,6 +3285,13 @@ impl<'a> EnumBuilder<'a> { } EnumVariation::ModuleConsts => { + let repr = match repr { + EnumRepr::Other(r) => r, + _ => { + panic!("Should never get this variant for module consts enum") + } + }; + let ident = Ident::new( CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site(), @@ -3213,7 +3311,7 @@ impl<'a> EnumBuilder<'a> { /// Add a variant to this enum. fn with_variant( - self, + mut self, ctx: &BindgenContext, variant: &EnumVariant, mangling_prefix: Option<&str>, @@ -3223,13 +3321,17 @@ impl<'a> EnumBuilder<'a> { ) -> Self { let variant_name = ctx.rust_mangle(variant.name()); let is_rust_enum = self.is_rust_enum(); - let expr = match variant.val() { + let (is_bool, expr) = match variant.val() { EnumVariantValue::Boolean(v) if is_rust_enum => { - helpers::ast_ty::uint_expr(v as u64) + (true, helpers::ast_ty::uint_expr(v as u64)) + } + EnumVariantValue::Boolean(v) => (true, quote!(#v)), + EnumVariantValue::Signed(v) => { + (false, helpers::ast_ty::int_expr(v)) + } + EnumVariantValue::Unsigned(v) => { + (false, helpers::ast_ty::uint_expr(v)) } - EnumVariantValue::Boolean(v) => quote!(#v), - EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v), - EnumVariantValue::Unsigned(v) => helpers::ast_ty::uint_expr(v), }; let mut doc = quote! {}; @@ -3242,22 +3344,40 @@ impl<'a> EnumBuilder<'a> { match self { EnumBuilder::Rust { - attrs, - ident, - tokens, - emitted_any_variants: _, + ref ident, + ref typedef, + ref mut const_tokens, + ref mut rustified_tokens, + ref mut safe_conversion_tokens, + ref mut emitted_any_variants, + .. } => { let name = ctx.rust_ident(variant_name); - EnumBuilder::Rust { - attrs, - ident, - tokens: quote! { - #tokens - #doc - #name = #expr, - }, - emitted_any_variants: true, - } + let const_name = Ident::new( + format!("{}_{}", ident.to_string(), name.to_string()) + .as_str(), + Span::call_site(), + ); + let add_as = if is_bool { + quote! { as #typedef } + } else { + quote!() + }; + const_tokens.push(quote! { + #doc + pub const #const_name: #typedef = #expr #add_as ; + }); + rustified_tokens.push(quote! { + #doc + #name = #expr , + }); + safe_conversion_tokens.push(quote! { + #expr => #ident::#name , + }); + + *emitted_any_variants = true; + + self } EnumBuilder::NewType { @@ -3339,21 +3459,75 @@ impl<'a> EnumBuilder<'a> { EnumBuilder::Rust { attrs, ident, - tokens, + typedef, + const_tokens, + rustified_tokens, + safe_conversion_tokens, emitted_any_variants, + safe_conversion, + unsafe_conversion, .. } => { let variants = if !emitted_any_variants { - quote!(__bindgen_cannot_repr_c_on_empty_enum = 0) + vec![quote!(__bindgen_cannot_repr_c_on_empty_enum = 0)] + } else { + rustified_tokens + }; + + let safe_conversion = if safe_conversion { + let prefix = ctx.trait_prefix(); + let error_type = Ident::new( + format!("{}Error", ident.to_string()).as_str(), + Span::call_site(), + ); + quote! { + pub struct #error_type(#typedef); + + impl #error_type { + #[must_use] + pub fn value(&self) -> #typedef { + self.0 + } + } + + impl #prefix::convert::TryFrom<#typedef> for #ident { + type Error = #error_type; + + fn try_from(v: #typedef) -> Result { + match v { + #( #safe_conversion_tokens )* + _ => #error_type(v) + } + } + } + } } else { - tokens + quote!() + }; + + let unsafe_conversion = if unsafe_conversion { + quote! { + impl #ident { + const unsafe fn from_ctype_unchecked(v: #typedef) -> Self { + std::mem::transmute(v) + } + } + } + } else { + quote!() }; quote! { + #( #const_tokens )* + #( #attrs )* pub enum #ident { - #variants + #( #variants )* } + + #safe_conversion + + #unsafe_conversion } } EnumBuilder::NewType { @@ -3428,6 +3602,76 @@ impl<'a> EnumBuilder<'a> { } } +fn handle_tranlation<'a>( + ctx: &BindgenContext, + layout: Option<&Layout>, + item: &Item, + repr: Option<&Type>, + translate: bool, +) -> syn::Type { + match repr { + Some(repr) + if !ctx.options().translate_enum_integer_types && !translate => + { + repr.to_rust_ty_or_opaque(ctx, item) + } + repr => { + // An enum's integer type is translated to a native Rust + // integer type in 3 cases: + // * the enum is Rustified and we need a translated type for + // the repr attribute + // * the representation couldn't be determined from the C source + // * it was explicitly requested as a bindgen option + + let kind = match repr { + Some(repr) => match *repr.canonical_type(ctx).kind() { + TypeKind::Int(int_kind) => int_kind, + _ => panic!("Unexpected type as enum repr"), + }, + None => { + warn!( + "Guessing type of enum! Forward declarations of enums \ + shouldn't be legal!" + ); + IntKind::Int + } + }; + + let signed = kind.is_signed(); + let size = layout + .map(|l| l.size) + .or_else(|| kind.known_size()) + .unwrap_or(0); + + let translated = match (signed, size) { + (true, 1) => IntKind::I8, + (false, 1) => IntKind::U8, + (true, 2) => IntKind::I16, + (false, 2) => IntKind::U16, + (true, 4) => IntKind::I32, + (false, 4) => IntKind::U32, + (true, 8) => IntKind::I64, + (false, 8) => IntKind::U64, + _ => { + warn!( + "invalid enum decl: signed: {}, size: {}", + signed, size + ); + IntKind::I32 + } + }; + + Type::new(None, None, TypeKind::Int(translated), false) + .to_rust_ty_or_opaque(ctx, item) + } + } +} + +enum EnumRepr { + Rust(syn::Type, syn::Type), + Other(syn::Type), +} + impl CodeGenerator for Enum { type Extra = Item; type Return = (); @@ -3447,71 +3691,37 @@ impl CodeGenerator for Enum { let layout = enum_ty.layout(ctx); let variation = self.computed_enum_variation(ctx, item); - let repr_translated; - let repr = match self.repr().map(|repr| ctx.resolve_type(repr)) { - Some(repr) - if !ctx.options().translate_enum_integer_types && - !variation.is_rust() => - { - repr - } - repr => { - // An enum's integer type is translated to a native Rust - // integer type in 3 cases: - // * the enum is Rustified and we need a translated type for - // the repr attribute - // * the representation couldn't be determined from the C source - // * it was explicitly requested as a bindgen option - - let kind = match repr { - Some(repr) => match *repr.canonical_type(ctx).kind() { - TypeKind::Int(int_kind) => int_kind, - _ => panic!("Unexpected type as enum repr"), - }, - None => { - warn!( - "Guessing type of enum! Forward declarations of enums \ - shouldn't be legal!" - ); - IntKind::Int - } - }; - - let signed = kind.is_signed(); - let size = layout - .map(|l| l.size) - .or_else(|| kind.known_size()) - .unwrap_or(0); - - let translated = match (signed, size) { - (true, 1) => IntKind::I8, - (false, 1) => IntKind::U8, - (true, 2) => IntKind::I16, - (false, 2) => IntKind::U16, - (true, 4) => IntKind::I32, - (false, 4) => IntKind::U32, - (true, 8) => IntKind::I64, - (false, 8) => IntKind::U64, - _ => { - warn!( - "invalid enum decl: signed: {}, size: {}", - signed, size - ); - IntKind::I32 - } - }; - - repr_translated = - Type::new(None, None, TypeKind::Int(translated), false); - &repr_translated - } + let repr = if variation.is_rust() { + EnumRepr::Rust( + handle_tranlation( + ctx, + layout.as_ref(), + item, + self.repr().map(|repr| ctx.resolve_type(repr)), + false, + ), + handle_tranlation( + ctx, + layout.as_ref(), + item, + self.repr().map(|repr| ctx.resolve_type(repr)), + true, + ), + ) + } else { + EnumRepr::Other(handle_tranlation( + ctx, + layout.as_ref(), + item, + self.repr().map(|repr| ctx.resolve_type(repr)), + false, + )) }; - let mut attrs = vec![]; // TODO(emilio): Delegate this to the builders? match variation { - EnumVariation::Rust { non_exhaustive } => { + EnumVariation::Rust { non_exhaustive, .. } => { if non_exhaustive && ctx.options().rust_features().non_exhaustive { @@ -3603,7 +3813,6 @@ impl CodeGenerator for Enum { }); } - let repr = repr.to_rust_ty_or_opaque(ctx, item); let has_typedef = ctx.is_enum_typedef_combo(item.id()); let mut builder = diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 70cf0eae88..c080668804 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -9,6 +9,75 @@ use crate::ir::annotations::Annotations; use crate::parse::ParseError; use crate::regex_set::RegexSet; +use std::fmt::{self, Display}; +use std::ops::Deref; +use std::str::FromStr; + +/// Represents option for rustified enum generation. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub enum RustEnumOption { + /// Add non-exhaustive attribute to Rust enum. + NonExhaustive, + /// Add safe TryFrom conversion from integer value. + TryFromRaw, + /// Provide an unsafe wrapper for transmute from integer value. + FromRawUnchecked, +} + +impl FromStr for RustEnumOption { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "non_exhaustive" => Ok(Self::NonExhaustive), + "try_from_raw" => Ok(Self::TryFromRaw), + "from_raw_unchecked" => Ok(Self::FromRawUnchecked), + _ => Err(format!( + "Invalid or unknown rustified struct option {:?}", + s + )), + } + } +} + +/// Collection of RustEnumOption values. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct RustEnumOptions(Vec); + +impl Deref for RustEnumOptions { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl FromStr for RustEnumOptions { + type Err = String; + + fn from_str(s: &str) -> Result { + Ok(RustEnumOptions( + s.split(",").filter(|s| s != &"").try_fold( + Vec::new(), + |mut vec, opt| { + vec.push(RustEnumOption::from_str(opt)?); + Result::<_, String>::Ok(vec) + }, + )?, + )) + } +} + +impl Display for RustEnumOption { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + RustEnumOption::NonExhaustive => write!(f, "non_exhaustive"), + RustEnumOption::TryFromRaw => write!(f, "try_from_raw"), + RustEnumOption::FromRawUnchecked => write!(f, "from_raw_unchecked"), + } + } +} + /// An enum representing custom handling that can be given to a variant. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum EnumVariantCustomBehavior { @@ -209,22 +278,6 @@ impl Enum { is_bitfield: false, is_global: true, } - } else if self.is_matching_enum( - ctx, - &ctx.options().rustified_enums, - item, - ) { - EnumVariation::Rust { - non_exhaustive: false, - } - } else if self.is_matching_enum( - ctx, - &ctx.options().rustified_non_exhaustive_enums, - item, - ) { - EnumVariation::Rust { - non_exhaustive: true, - } } else if self.is_matching_enum( ctx, &ctx.options().constified_enums, @@ -232,7 +285,22 @@ impl Enum { ) { EnumVariation::Consts } else { - ctx.options().default_enum_style + let matches = ctx + .options() + .rustified_enums + .iter() + .find(|(_, regex)| self.is_matching_enum(ctx, regex, item)); + match matches { + Some((options, _)) => EnumVariation::Rust { + non_exhaustive: options + .contains(&RustEnumOption::NonExhaustive), + safe_conversion: options + .contains(&RustEnumOption::TryFromRaw), + unsafe_conversion: options + .contains(&RustEnumOption::FromRawUnchecked), + }, + None => ctx.options().default_enum_style, + } } } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3bf0bc3c1d..e1158f2911 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -54,6 +54,7 @@ pub use codegen::{ pub use features::RUST_TARGET_STRINGS; pub use features::{RustTarget, LATEST_STABLE_RUST}; pub use ir::annotations::FieldVisibilityKind; +pub use ir::enum_ty::RustEnumOptions; pub use ir::function::Abi; pub use regex_set::RegexSet; @@ -440,7 +441,7 @@ impl Builder { impl BindgenOptions { fn build(&mut self) { - const REGEX_SETS_LEN: usize = 29; + const REGEX_SETS_LEN: usize = 27; let regex_sets: [_; REGEX_SETS_LEN] = [ &mut self.blocklisted_types, @@ -459,8 +460,6 @@ impl BindgenOptions { &mut self.constified_enum_modules, &mut self.newtype_enums, &mut self.newtype_global_enums, - &mut self.rustified_enums, - &mut self.rustified_non_exhaustive_enums, &mut self.type_alias, &mut self.new_type_alias, &mut self.new_type_alias_deref, @@ -477,7 +476,9 @@ impl BindgenOptions { let record_matches = self.record_matches; #[cfg(feature = "experimental")] { - let sets_len = REGEX_SETS_LEN + self.abi_overrides.len(); + let sets_len = REGEX_SETS_LEN + + self.abi_overrides.len() + + self.rustified_enums.len(); let names = if self.emit_diagnostics { <[&str; REGEX_SETS_LEN]>::into_iter([ "--blocklist-type", @@ -494,8 +495,6 @@ impl BindgenOptions { "--bitfield-enum", "--newtype-enum", "--newtype-global-enum", - "--rustified-enum", - "--rustified-enum-non-exhaustive", "--constified-enum-module", "--constified-enum", "--type-alias", @@ -511,6 +510,9 @@ impl BindgenOptions { "--must-use", ]) .chain((0..self.abi_overrides.len()).map(|_| "--override-abi")) + .chain( + (0..self.rustified_enums.len()).map(|_| "--rustified-enum"), + ) .map(Some) .collect() } else { @@ -527,6 +529,9 @@ impl BindgenOptions { for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { regex_set.build(record_matches); } + for regex_set in self.rustified_enums.values_mut() { + regex_set.build(record_matches); + } let rust_target = self.rust_target; #[allow(deprecated)] diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index e4c03ecd4d..727c91fc22 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -18,6 +18,7 @@ use crate::CodegenConfig; use crate::FieldVisibilityKind; use crate::Formatter; use crate::HashMap; +use crate::RustEnumOptions; use crate::DEFAULT_ANON_FIELDS_PREFIX; use std::env; @@ -454,7 +455,7 @@ options! { as_args: "--newtype-global-enum", }, /// `enum`s marked as Rust `enum`s. - rustified_enums: RegexSet { + rustified_enums: HashMap { methods: { regex_option! { /// Mark the given `enum` as a Rust `enum`. @@ -465,13 +466,21 @@ options! { /// **Use this with caution**, creating an instance of a Rust `enum` with an /// invalid value will cause undefined behaviour. To avoid this, use the /// [`Builder::newtype_enum`] style instead. - pub fn rustified_enum>(mut self, arg: T) -> Builder { - self.options.rustified_enums.insert(arg); + pub fn rustified_enum>(mut self, options: RustEnumOptions, arg: T) -> Builder { + self.options.rustified_enums.entry(options).or_default().insert(arg.into()); self } } }, - as_args: "--rustified-enum", + as_args: |overrides, args| { + for (options, set) in overrides { + let options = options.iter().map(|item| item.to_string()).collect::>(); + for item in set.get_items() { + args.push("--rustified-enum".to_owned()); + args.push(format!("{}={}", item, options.join(","))); + } + } + }, }, /// `enum`s marked as non-exhaustive Rust `enum`s. rustified_non_exhaustive_enums: RegexSet {