@@ -581,7 +581,7 @@ impl CodeGenerator for Module {
581
581
utils:: prepend_complex_type ( & mut * result) ;
582
582
}
583
583
if ctx. need_opaque_array_type ( ) {
584
- utils:: prepend_opaque_array_type ( & mut * result) ;
584
+ utils:: prepend_opaque_array_types ( & mut * result) ;
585
585
}
586
586
if result. saw_objc {
587
587
utils:: prepend_objc_header ( ctx, & mut * result) ;
@@ -2259,14 +2259,13 @@ impl CodeGenerator for CompInfo {
2259
2259
2260
2260
if has_address {
2261
2261
let layout = Layout :: new ( 1 , 1 ) ;
2262
- let ty = helpers:: blob ( ctx, Layout :: new ( 1 , 1 ) , false ) ;
2263
2262
struct_layout. saw_field_with_layout (
2264
2263
"_address" ,
2265
2264
layout,
2266
2265
/* offset = */ Some ( 0 ) ,
2267
2266
) ;
2268
2267
fields. push ( quote ! {
2269
- pub _address: #ty ,
2268
+ pub _address: u8 ,
2270
2269
} ) ;
2271
2270
}
2272
2271
}
@@ -2275,8 +2274,7 @@ impl CodeGenerator for CompInfo {
2275
2274
match layout {
2276
2275
Some ( l) => {
2277
2276
explicit_align = Some ( l. align ) ;
2278
-
2279
- let ty = helpers:: blob ( ctx, l, false ) ;
2277
+ let ty = helpers:: blob ( ctx, l) ;
2280
2278
fields. push ( quote ! {
2281
2279
pub _bindgen_opaque_blob: #ty ,
2282
2280
} ) ;
@@ -2310,9 +2308,9 @@ impl CodeGenerator for CompInfo {
2310
2308
explicit_align = Some ( layout. align ) ;
2311
2309
}
2312
2310
if !struct_layout. is_rust_union ( ) {
2313
- let ty = helpers:: blob ( ctx, layout, false ) ;
2311
+ let ty = helpers:: blob ( ctx, layout) ;
2314
2312
fields. push ( quote ! {
2315
- pub bindgen_union_field: #ty ,
2313
+ pub bindgen_union_field: #ty,
2316
2314
} ) ;
2317
2315
}
2318
2316
}
@@ -4069,7 +4067,7 @@ pub(crate) trait TryToOpaque {
4069
4067
extra : & Self :: Extra ,
4070
4068
) -> error:: Result < syn:: Type > {
4071
4069
self . try_get_layout ( ctx, extra)
4072
- . map ( |layout| helpers:: blob ( ctx, layout, true ) )
4070
+ . map ( |layout| helpers:: blob ( ctx, layout) )
4073
4071
}
4074
4072
}
4075
4073
@@ -4095,7 +4093,7 @@ pub(crate) trait ToOpaque: TryToOpaque {
4095
4093
extra : & Self :: Extra ,
4096
4094
) -> syn:: Type {
4097
4095
let layout = self . get_layout ( ctx, extra) ;
4098
- helpers:: blob ( ctx, layout, true )
4096
+ helpers:: blob ( ctx, layout)
4099
4097
}
4100
4098
}
4101
4099
@@ -4146,7 +4144,7 @@ where
4146
4144
) -> error:: Result < syn:: Type > {
4147
4145
self . try_to_rust_ty ( ctx, extra) . or_else ( |_| {
4148
4146
if let Ok ( layout) = self . try_get_layout ( ctx, extra) {
4149
- Ok ( helpers:: blob ( ctx, layout, true ) )
4147
+ Ok ( helpers:: blob ( ctx, layout) )
4150
4148
} else {
4151
4149
Err ( Error :: NoLayoutForOpaqueBlob )
4152
4150
}
@@ -5610,23 +5608,34 @@ pub(crate) mod utils {
5610
5608
result. extend ( old_items) ;
5611
5609
}
5612
5610
5613
- pub ( crate ) fn prepend_opaque_array_type (
5611
+ pub ( crate ) fn prepend_opaque_array_types (
5614
5612
result : & mut Vec < proc_macro2:: TokenStream > ,
5615
5613
) {
5616
- let ty = quote ! {
5617
- /// If Bindgen could only determine the size and alignment of a
5618
- /// type, it is represented like this.
5619
- #[ derive( PartialEq , Copy , Clone , Debug , Hash ) ]
5620
- #[ repr( C ) ]
5621
- pub struct __BindgenOpaqueArray<T : Copy , const N : usize >( pub [ T ; N ] ) ;
5622
- impl <T : Copy + Default , const N : usize > Default for __BindgenOpaqueArray<T , N > {
5623
- fn default ( ) -> Self {
5624
- Self ( [ <T as Default >:: default ( ) ; N ] )
5614
+ let mut tys = vec ! [ ] ;
5615
+ // If Bindgen could only determine the size and alignment of a type, it is represented like
5616
+ // this. We could use const generics or so but it wouldn't support all our rust targets. We
5617
+ // only expect [u8; N] as the type parameter. FIXME(emilio): Probably generate only the
5618
+ // ones we want.
5619
+ for align in [ 1usize , 2 , 4 , 8 , 16 ] {
5620
+ let ident = format_ident ! ( "__BindgenOpaqueArray{}" , align) ;
5621
+ let repr = if align == 1 {
5622
+ quote ! { #[ repr( C ) ] }
5623
+ } else {
5624
+ let explicit = super :: helpers:: ast_ty:: int_expr ( align as i64 ) ;
5625
+ quote ! { #[ repr( C , align( #explicit) ) ] }
5626
+ } ;
5627
+ tys. push ( quote ! {
5628
+ #[ derive( PartialEq , Eq , Copy , Clone , Debug , Hash ) ]
5629
+ #repr
5630
+ pub struct #ident<T >( pub T ) ;
5631
+ impl <const N : usize > Default for #ident<[ u8 ; N ] > {
5632
+ fn default ( ) -> Self {
5633
+ Self ( [ 0u8 ; N ] )
5634
+ }
5625
5635
}
5626
- }
5627
- } ;
5628
-
5629
- result. insert ( 0 , ty) ;
5636
+ } )
5637
+ }
5638
+ result. splice ( 0 ..0 , tys) ;
5630
5639
}
5631
5640
5632
5641
pub ( crate ) fn build_path (
0 commit comments