summaryrefslogtreecommitdiff
path: root/bindgen-integration/cpp/Test.h
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-11-23 04:31:10 -0600
committerGitHub <noreply@github.com>2017-11-23 04:31:10 -0600
commit7c3584d7bc328a01ae5352e191f1fd41bb7fb1a9 (patch)
treeace279bfdbd625d446074c01b958d7b4d44c729a /bindgen-integration/cpp/Test.h
parente3e6c730393f97daae93c2394d4af7bc9a5183b4 (diff)
parentf0e05310b43e88e541ed011d20994c02fdcc1a3a (diff)
Auto merge of #1158 - glyn:large-bitfield-units, r=emilio
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. It is assumed that the alignment of the `Storage` type is no larger than the alignment of the `Align` type, which will be true if the `Storage` type is, for example, 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 `__BindgenBitfieldUnit` and code to integrate it into bindgen. r? @emilio
Diffstat (limited to 'bindgen-integration/cpp/Test.h')
-rw-r--r--bindgen-integration/cpp/Test.h18
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