summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-08-14 07:20:23 -0500
committerGitHub <noreply@github.com>2017-08-14 07:20:23 -0500
commitf9087f3bb48eccf23f9388885a99b19ee18d41e7 (patch)
tree604bea52d3dc0ee6aa798191e6610c4924d1ed04 /src/codegen/mod.rs
parent5d53f85fa96b7c7d86ba3291c80d6014f27938d6 (diff)
parent7603eb1926ba8fcecfcac4d7bb55269703406c53 (diff)
Auto merge of #909 - bkchr:union_fix, r=emilio
Fixes alignment errors with new Rust union type This fix creates a new private field with the required aligned size. This new private field ensures that the union has the required size. This fixes: #908
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 3f5ceaaa..886f3860 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1612,14 +1612,20 @@ impl CodeGenerator for CompInfo {
);
}
- if is_union && !self.can_be_rust_union(ctx) {
+ if is_union {
let layout = layout.expect("Unable to get layout information?");
let ty = BlobTyBuilder::new(layout).build();
- let field = StructFieldBuilder::named("bindgen_union_field")
- .pub_()
- .build_ty(ty);
+
+ let field = if self.can_be_rust_union(ctx) {
+ StructFieldBuilder::named("_bindgen_union_align")
+ .build_ty(ty)
+ } else {
+ struct_layout.saw_union(layout);
- struct_layout.saw_union(layout);
+ StructFieldBuilder::named("bindgen_union_field")
+ .pub_()
+ .build_ty(ty)
+ };
fields.push(field);
}