Skip to content

Commit 0267b0e

Browse files
GKFXpvdrz
authored andcommitted
Wrap the array representation of opaque types in a #[repr(C)] struct
1 parent b23d978 commit 0267b0e

File tree

15 files changed

+157
-23
lines changed

15 files changed

+157
-23
lines changed

bindgen-integration/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn test_item_rename() {
254254
#[test]
255255
fn test_matching_with_rename() {
256256
assert_eq!(bindings::enum_to_be_constified_THREE, 3);
257-
assert_eq!(unsafe { bindings::TEMPLATED_CONST_VALUE.len() }, 30);
257+
assert_eq!(unsafe { bindings::TEMPLATED_CONST_VALUE.0.len() }, 30);
258258
}
259259

260260
#[test]

bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/non-type-params.rs

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/size_t_template.rs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// bindgen-flags: -- --target=aarch64-unknown-linux-gnu
2+
3+
typedef __builtin_va_list va_list;
4+
int vprintf(const char* format, va_list vlist);

bindgen/codegen/helpers.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@ pub(crate) mod attributes {
7575
}
7676
}
7777

78-
/// Generates a proper type for a field or type with a given `Layout`, that is,
79-
/// a type with the correct size and alignment restrictions.
80-
pub(crate) fn blob(layout: Layout) -> syn::Type {
78+
/// The `ffi_safe` argument should be true if this is a type that the user might
79+
/// reasonably use, e.g. not struct padding, where the __BindgenOpaqueArray is
80+
/// just noise.
81+
/// TODO: Should this be `MaybeUninit`, since padding bytes are effectively
82+
/// uninitialized?
83+
pub(crate) fn blob(
84+
ctx: &BindgenContext,
85+
layout: Layout,
86+
ffi_safe: bool,
87+
) -> syn::Type {
8188
let opaque = layout.opaque();
8289

8390
// FIXME(emilio, #412): We fall back to byte alignment, but there are
@@ -93,7 +100,12 @@ pub(crate) fn blob(layout: Layout) -> syn::Type {
93100

94101
if data_len == 1 {
95102
ty
103+
} else if ffi_safe && ctx.options().rust_features().min_const_generics {
104+
ctx.generated_opaque_array();
105+
syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> }
96106
} else {
107+
// This is not FFI safe as an argument; the struct above is
108+
// preferable.
97109
syn::parse_quote! { [ #ty ; #data_len ] }
98110
}
99111
}

0 commit comments

Comments
 (0)