Default to generating constified enums, rather than generating Rust enums #758
Description
Right now, we translate C/C++ enums into Rust enums by default. This is problematic because it is OK for C/C++ code to return some int
that isn't one of the enum variants, and that is well defined for C/C++; however, that is UB in Rust and can lead to miscompilations. People shouldn't be using Rust enums unless they have complete control of the C/C++ code (ie not using a shared library and have audited the C/C++ code themselves). Therefore, it definitely shouldn't be the default!
The changes involved are to
-
replace the
Builder::constified_enum
method with aBuilder::rustified_enum
method insrc/lib.rs
-
replace the
--constified-enum
flag with a--rustified-enum
flag insrc/options.rs
-
update the way we determine if an enum is constified or a rust enum in
src/codegen/mod.rs
. Do agit grep constified src/codegen
to see the relevant code paths. -
For all the test header files in
tests/headers/*
that contain enums and do not have a--constified-enum
flag in the// bindgen-flags:
comment, add a--rustified-enum .*
to the// bindgen-flags:
comment -
Remove
--constified-enum whatever
flags from all test headers in thetests/headers/*
files
Activity