Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't wrap struct padding in __bindgen_marker_Opaque #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,12 +2362,9 @@ impl CodeGenerator for CompInfo {

if has_address {
let layout = Layout::new(1, 1);
// Normally for opaque data we use helpers::blob,
// which may wrap it in __bindgen_marker_Opaque<T>.
// Downstream tools may then use this as a sign that
// the type is complex or can't be stack-allocated,
// etc. But in this case this one-byte field is harmless
// so we'll just represent it without that extra marker.
// Don't use __bindgen_marker_Opaque for this harmless one-byte
// field. See StructLayoutTracker::padding_field() for a longer
// explanation of blob_inner() vs blob().
let ty = helpers::blob_inner(ctx, Layout::new(1, 1), false);
struct_layout.saw_field_with_layout(
"_address",
Expand Down
7 changes: 6 additions & 1 deletion bindgen/codegen/struct_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ impl<'a> StructLayoutTracker<'a> {
}

fn padding_field(&mut self, layout: Layout) -> proc_macro2::TokenStream {
let ty = helpers::blob(self.ctx, layout, false);
// Normally for opaque data we use helpers::blob(), which may wrap it
// __bindgen_marker_Opaque<T>. Downstream tools may then use this as a
// sign that the type is complex or can't be stack-allocated, etc. But
// in this case the padding is just plain data, so we want to represent
// it without the extra marker.
let ty = helpers::blob_inner(self.ctx, layout, false);
let padding_count = self.padding_count;

self.padding_count += 1;
Expand Down