Skip to content
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

Use u32 to represent most flags and enum types. #701

Merged
merged 1 commit into from
Jun 20, 2023
Merged

Conversation

sunfishcode
Copy link
Member

This makes the types consistent between the linux_raw and libc backends. And, using unsigned types for flags is more idiomatic for Rust.

To avoid the risk of as silently casting away bits, introduce new bitcast and bitflags_bits macros which convert their argument to the needed integer type while only changing its signedness interpretation.

These macros use transmute internally, to ensure that the source and destination are the same size, so they also include code to prevent them from being used on non-integer types.

@sunfishcode sunfishcode force-pushed the sunfishcode/flags branch 2 times, most recently from b0b095b to 3711916 Compare June 19, 2023 23:58
This makes the types consistent between the linux_raw and libc backends.
And, using unsigned types for flags is more idiomatic for Rust.

To avoid the risk of `as` silently casting away bits, introduce new
`bitcast` and `bitflags_bits` macros which convert their argument to the
needed integer type while only changing its signedness interpretation.
@sunfishcode sunfishcode merged commit 540f1f3 into main Jun 20, 2023
@sunfishcode sunfishcode deleted the sunfishcode/flags branch June 20, 2023 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant