Skip to content

Commit 63623b7

Browse files
committed
Fix size of union CArray
1 parent 167db9c commit 63623b7

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

bindgen/visitor/TreeVisitor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ void TreeVisitor::handleUnion(clang::RecordDecl *record, std::string name) {
108108
std::vector<Field> fields;
109109

110110
for (const clang::FieldDecl *field : record->fields()) {
111-
maxSize = std::max(maxSize, astContext->getTypeSize(field->getType()));
111+
uint64_t sizeInBytes = astContext->getTypeSize(field->getType()) / 8;
112+
maxSize = std::max(maxSize, sizeInBytes);
112113
std::string fname = field->getNameAsString();
113114
std::string ftype = handleReservedWords(
114115
typeTranslator.Translate(field->getType(), &name));

tests/samples/PrivateMembers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object PrivateMembers {
1616
type struct_structWithPrivateStruct = native.CStruct1[native.Ptr[struct_structWithPrivateType]]
1717
type struct_normalStruct = native.CStruct1[native.CInt]
1818
type struct_privateStructWithTypedef = native.CStruct1[native.Ptr[__private_type]]
19-
type union___unionWithPrivateName = native.CArray[Byte, native.Nat.Digit[native.Nat._3, native.Nat._2]]
19+
type union___unionWithPrivateName = native.CArray[Byte, native.Nat._4]
2020
def getTypeThatUsesPrivateTypes(): pid_t = native.extern
2121
def getPrivateType(): native.Ptr[__private_type] = native.extern
2222
def usesPrivateUnion(anonymous0: union___unionWithPrivateName): Unit = native.extern

tests/samples/ReservedWords.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object ReservedWords {
1515
type `finally` = struct_finally
1616
type struct_object = native.CStruct2[`match`, native.CInt]
1717
type struct_finally = native.CStruct2[`def`, `lazy`]
18-
type union_lazy = native.CArray[Byte, native.Nat.Digit[native.Nat._1, native.Nat.Digit[native.Nat._2, native.Nat._8]]]
18+
type union_lazy = native.CArray[Byte, native.Nat.Digit[native.Nat._1, native.Nat._6]]
1919
def `with`(`sealed`: `match`, `implicit`: native.Ptr[`match`], `forSome`: `lazy`): `type` = native.extern
2020
def `implicit`(`type`: native.Ptr[`finally`]): `match` = native.extern
2121
def _1(): Unit = native.extern

tests/samples/Union.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.scalanative.native._
66
@native.link("bindgentests")
77
@native.extern
88
object Union {
9-
type union_values = native.CArray[Byte, native.Nat.Digit[native.Nat._6, native.Nat._4]]
9+
type union_values = native.CArray[Byte, native.Nat._8]
1010
def getValues(): native.Ptr[union_values] = native.extern
1111
}
1212

0 commit comments

Comments
 (0)