Skip to content

Commit

Permalink
Refactor requires_explicit_align
Browse files Browse the repository at this point in the history
  • Loading branch information
pepyakin committed Oct 11, 2017
1 parent 8315646 commit 2a57d7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,10 +1612,13 @@ impl CodeGenerator for CompInfo {
fields.push(padding_field);
}

if let Some(align_field) =
layout.and_then(|layout| struct_layout.align_struct(layout))
{
fields.push(align_field);
if let Some(layout) = layout {
if struct_layout.requires_explicit_align(layout) {
let ty = helpers::blob(Layout::new(0, layout.align));
fields.push(quote! {
pub __bindgen_align: #ty ,
});
}
}
}

Expand Down
13 changes: 2 additions & 11 deletions src/codegen/struct_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,9 @@ impl<'a> StructLayoutTracker<'a> {
}
}

pub fn align_struct(&self, layout: Layout) -> Option<quote::Tokens> {
if self.max_field_align < layout.align &&
pub fn requires_explicit_align(&self, layout: Layout) -> bool {
self.max_field_align < layout.align &&
layout.align <= mem::size_of::<*mut ()>()
{
let ty = helpers::blob(Layout::new(0, layout.align));

Some(quote! {
pub __bindgen_align: #ty ,
})
} else {
None
}
}

fn padding_bytes(&self, layout: Layout) -> usize {
Expand Down

0 comments on commit 2a57d7c

Please sign in to comment.