diff options
author | Bastian Köcher <git@kchr.de> | 2017-08-13 18:10:56 +0200 |
---|---|---|
committer | Bastian Köcher <git@kchr.de> | 2017-08-14 13:19:56 +0200 |
commit | 7603eb1926ba8fcecfcac4d7bb55269703406c53 (patch) | |
tree | 36a4593fffd45c9baab5abfe919637ad66a9e8ba /src/codegen/mod.rs | |
parent | 8c71eed3ad740d736c8d6425c3910cf0e06e8004 (diff) |
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.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 16 |
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); } |