Skip to content

Remove uses of enum #4419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tgross35 opened this issue Apr 15, 2025 · 0 comments
Open

Remove uses of enum #4419

tgross35 opened this issue Apr 15, 2025 · 0 comments
Labels
I-unsound 💥 A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Milestone

Comments

@tgross35
Copy link
Contributor

Rust enums become UB if they hold an unexpected value, while C enums are effectively a grouped list of named constants. This causes easy UB if e.g. C adds a value or returns a value not represented by the enum (as is allowed in C), and this value gets passed to Rust.

The easiest thing to do is map enums to constants, which we already do in most cases. We could also consider an enum! macro that figures out the values.

Some more context is at https://mdaverde.com/posts/rust-bindgen-enum/ and rust-lang/rust-bindgen#2646.

@tgross35 tgross35 added the I-unsound 💥 A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label Apr 15, 2025
@tgross35 tgross35 added this to the 1.0 milestone Apr 15, 2025
tgross35 added a commit to tgross35/rust-libc that referenced this issue Apr 15, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
tgross35 added a commit to tgross35/rust-libc that referenced this issue Apr 15, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
tgross35 added a commit to tgross35/rust-libc that referenced this issue Apr 15, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
tgross35 added a commit to tgross35/rust-libc that referenced this issue Apr 16, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
tgross35 added a commit to tgross35/rust-libc that referenced this issue Apr 16, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
tgross35 added a commit to tgross35/rust-libc that referenced this issue Apr 16, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
sanstzu pushed a commit to sanstzu/rust-libc that referenced this issue May 16, 2025
Our current `e!` macro makes it easy to run into UB if C headers add a
variant that isn't represented in the Rust version. Add a path to
migrate away from this by introducing the `c_enum!` macro which
represents a C enum as Rust constants and a type alias.

Part of [1].

[1]: rust-lang#4419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-unsound 💥 A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Projects
None yet
Development

No branches or pull requests

1 participant