Skip to content

Default to generating constified enums, rather than generating Rust enums #758

Closed
@fitzgen

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 a Builder::rustified_enum method in src/lib.rs

  • replace the --constified-enum flag with a --rustified-enum flag in src/options.rs

  • update the way we determine if an enum is constified or a rust enum in src/codegen/mod.rs. Do a git 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 the tests/headers/* files

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions