Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport bitfield allocation units larger than 64 bits #1158
Conversation
highfive
assigned
fitzgen
Nov 20, 2017
highfive
added
the
S-awaiting-review
label
Nov 20, 2017
This comment has been minimized.
This comment has been minimized.
emilio
reviewed
Nov 20, 2017
| @@ -0,0 +1,83 @@ | |||
| #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] | |||
| pub struct BindgenBitfieldUnit<Storage, Align> | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
emilio
Nov 20, 2017
Collaborator
Also, I'd recommend maybe to put a double underscore as the prefix for the name, since that's technically reserved in C. Not sure what's @fitzgen's opinion on that.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? @emilio |
highfive
assigned
emilio
and unassigned
fitzgen
Nov 21, 2017
emilio
reviewed
Nov 21, 2017
|
looks pretty nice to me, but I think it can merge as-is. at least the use_core issue needs to be resolved. Maybe we can just get away fine without const fn... |
| { | ||
| #[inline] | ||
| pub fn new(storage: Storage) -> Self { | ||
| use std::mem::align_of; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
glyn
Nov 21, 2017
Author
Contributor
@emilio The simplest solution is to remove the assertion (and its use of align_of) as it's not needed currently and it's very unlikely that anyone will trip over the assumption in the future.
| #[inline] | ||
| pub fn new(storage: Storage) -> Self { | ||
| use std::mem::align_of; | ||
| debug_assert!(align_of::<Storage>() <= align_of::<Align>()); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
glyn
Nov 21, 2017
Author
Contributor
@emilio The simplest solution is to remove the assertion as it's not needed currently and it's very unlikely that anyone will trip over the assumption in the future.
| @@ -140,8 +140,6 @@ macro_rules! rust_feature_def { | |||
| rust_feature_def!( | |||
| /// Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md)) | |||
| => untagged_union; | |||
| /// Constant function ([RFC 911](https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md)) | |||
| => const_fn; | |||
This comment has been minimized.
This comment has been minimized.
emilio
Nov 21, 2017
Collaborator
I think const fn was also needed for SpiderMonkey, so not sure we can get away without it so easily...
This comment has been minimized.
This comment has been minimized.
glyn
Nov 21, 2017
Author
Contributor
@emilio I'll leave it out for now because it would be easy to add back in. Certainly the bitfield allocation unit constructors have no hope of being const fn.
| this->nMonthDay == nMonthDay && | ||
| this->nMonth == nMonth && | ||
| this->byte == byte; | ||
| printf("\n"); |
This comment has been minimized.
This comment has been minimized.
emilio
Nov 21, 2017
Collaborator
Not sure how worth are the printfs? i'd usually just use gdb for this.
This comment has been minimized.
This comment has been minimized.
glyn
Nov 21, 2017
Author
Contributor
@emilio Agreed. Better to delete this clutter. It's trivial to add back in for debugging if someone doesn't have gdb.
This comment has been minimized.
This comment has been minimized.
|
I took a closer look, and I can't think of why this shouldn't get merged. Thanks a lot @glyn! @bors-servo r+ |
This comment has been minimized.
This comment has been minimized.
|
|
highfive
added
S-awaiting-merge
and removed
S-awaiting-review
labels
Nov 23, 2017
This comment has been minimized.
This comment has been minimized.
bors-servo
added a commit
that referenced
this pull request
Nov 23, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors-servo
merged commit f0e0531
into
rust-lang:master
Nov 23, 2017
highfive
removed
the
S-awaiting-merge
label
Nov 23, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for taking this over the finishing line @glyn! We should probably go back and re-test all of our bitfield bugs and see if we fixed any of them with this change. |
glyn commentedNov 20, 2017
•
edited
Individual bitfields are still limited to at most 64 bits, but this restriction can be weakened when Rust supports
u128.This implements issue #816.
Usage notes:
more than one binding may need to work around the duplication by including
each binding in its own module.
directly to the corresponding struct fields with no need for transmutation.
Implementation notes:
__BindgenBitfieldUnitrepresents a bitfield allocation unit using aStoragetype accessible as a slice of
u8. The alignment of the unit is inherited froman
Aligntype by virtue of the field:The position of this field in the struct is irrelevant.
It is assumed that the alignment of the
Storagetype is no larger than thealignment of the
Aligntype, which will be true if theStoragetype is, forexample, an array of
u8. This assumption is checked in a debug assertion.Although the double underscore (__) prefix is reserved for implementations of
C++, there are precedents for this convention elsewhere in bindgen and so the
convention is adopted here too.
Acknowledgement:
Thanks to @fitzgen for an initial implementation of
__BindgenBitfieldUnitandcode to integrate it into bindgen.
r? @emilio