-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Labels
I-unsound 💥
A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Milestone
Comments
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
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.
The text was updated successfully, but these errors were encountered: