-
Notifications
You must be signed in to change notification settings - Fork 56
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
Improve usage of repr(packed) #68
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Will hold off on merging for a day in case @IsaacWoods wants to review, as I've been less involved in the project lately.
Maybe outside of the scope of this PR, but should there be compile-time validations or tests to make sure the structs are the right size? In my project i have a couple of fn _test_size() {
unsafe {
core::mem::transmute::<[u8; 56], Hpet>([0u8; 56]);
}
} Which give a compile-time check to validate the Enforcing this would make sure that changes by humans or compilers will get noticed instead of loading wrongly-sized structs from memory pointers. |
@VictorKoenders I completely agree. I will add those tests to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests
Close #38.
We occasionally use
repr(packed)
when the struct is unaligned. When we use it, I added a comment explaining why. In addition, we deriveCopy
andClone
to allow the compiler to copy the fields to locals.