diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-10-25 17:31:21 -0700 |
---|---|---|
committer | Glyn Normington <gnormington@pivotal.io> | 2017-11-21 13:55:00 +0000 |
commit | f0e05310b43e88e541ed011d20994c02fdcc1a3a (patch) | |
tree | be05ee8a3fa1a1d7f696daa630e48a824276ff61 /bindgen-integration/cpp/Test.h | |
parent | 5e0cf9c356960e0459fea22cf0754dbec66f58b4 (diff) |
Support bitfield allocation units larger than 64 bits
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:
* Since common code is added to each generated binding, a program which uses
more than one binding may need to work around the duplication by including
each binding in its own module.
* The values created by bitfield allocation unit constructors can be assigned
directly to the corresponding struct fields with no need for transmutation.
Implementation notes:
__BindgenBitfieldUnit represents a bitfield allocation unit using a Storage
type accessible as a slice of u8. The alignment of the unit is inherited from
an Align type by virtue of the field:
align: [Align; 0],
The position of this field in the struct is irrelevant.
The alignment of the Storage type is intended to be no larger than the
alignment of the Align type, which will be true if the Storage type is, for
example, an array of u8.
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 __BindgenBitfieldUnit and
code to integrate it into bindgen.
Diffstat (limited to 'bindgen-integration/cpp/Test.h')
-rw-r--r-- | bindgen-integration/cpp/Test.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index e23a32e6..7ddb98bd 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -121,6 +121,24 @@ struct Sixth { unsigned char nMonthDay); }; +struct Seventh { + bool first_one_bit : 1; + unsigned int second_thirty_bits : 30; + unsigned short third_two_bits : 2; + unsigned int fourth_thirty_bits : 30; + unsigned short fifth_two_bits : 2; + bool sixth_one_bit : 1; + unsigned int seventh_thirty_bits : 30; + + /// Returns true if the bitfields match the arguments, false otherwise. + bool assert(bool first, + int second, + unsigned short third, + unsigned int fourth, + unsigned short fifth, + bool sixth, + int seventh); +}; } // namespace bitfields |