@@ -581,7 +581,7 @@ impl CodeGenerator for Module {
581581 utils:: prepend_complex_type ( & mut * result) ;
582582 }
583583 if ctx. need_opaque_array_type ( ) {
584- utils:: prepend_opaque_array_type ( & mut * result) ;
584+ utils:: prepend_opaque_array_types ( & mut * result) ;
585585 }
586586 if result. saw_objc {
587587 utils:: prepend_objc_header ( ctx, & mut * result) ;
@@ -2259,14 +2259,13 @@ impl CodeGenerator for CompInfo {
22592259
22602260 if has_address {
22612261 let layout = Layout :: new ( 1 , 1 ) ;
2262- let ty = helpers:: blob ( ctx, Layout :: new ( 1 , 1 ) , false ) ;
22632262 struct_layout. saw_field_with_layout (
22642263 "_address" ,
22652264 layout,
22662265 /* offset = */ Some ( 0 ) ,
22672266 ) ;
22682267 fields. push ( quote ! {
2269- pub _address: #ty ,
2268+ pub _address: u8 ,
22702269 } ) ;
22712270 }
22722271 }
@@ -2275,8 +2274,7 @@ impl CodeGenerator for CompInfo {
22752274 match layout {
22762275 Some ( l) => {
22772276 explicit_align = Some ( l. align ) ;
2278-
2279- let ty = helpers:: blob ( ctx, l, false ) ;
2277+ let ty = helpers:: blob ( ctx, l) ;
22802278 fields. push ( quote ! {
22812279 pub _bindgen_opaque_blob: #ty ,
22822280 } ) ;
@@ -2310,9 +2308,9 @@ impl CodeGenerator for CompInfo {
23102308 explicit_align = Some ( layout. align ) ;
23112309 }
23122310 if !struct_layout. is_rust_union ( ) {
2313- let ty = helpers:: blob ( ctx, layout, false ) ;
2311+ let ty = helpers:: blob ( ctx, layout) ;
23142312 fields. push ( quote ! {
2315- pub bindgen_union_field: #ty ,
2313+ pub bindgen_union_field: #ty,
23162314 } ) ;
23172315 }
23182316 }
@@ -4069,7 +4067,7 @@ pub(crate) trait TryToOpaque {
40694067 extra : & Self :: Extra ,
40704068 ) -> error:: Result < syn:: Type > {
40714069 self . try_get_layout ( ctx, extra)
4072- . map ( |layout| helpers:: blob ( ctx, layout, true ) )
4070+ . map ( |layout| helpers:: blob ( ctx, layout) )
40734071 }
40744072}
40754073
@@ -4095,7 +4093,7 @@ pub(crate) trait ToOpaque: TryToOpaque {
40954093 extra : & Self :: Extra ,
40964094 ) -> syn:: Type {
40974095 let layout = self . get_layout ( ctx, extra) ;
4098- helpers:: blob ( ctx, layout, true )
4096+ helpers:: blob ( ctx, layout)
40994097 }
41004098}
41014099
@@ -4146,7 +4144,7 @@ where
41464144 ) -> error:: Result < syn:: Type > {
41474145 self . try_to_rust_ty ( ctx, extra) . or_else ( |_| {
41484146 if let Ok ( layout) = self . try_get_layout ( ctx, extra) {
4149- Ok ( helpers:: blob ( ctx, layout, true ) )
4147+ Ok ( helpers:: blob ( ctx, layout) )
41504148 } else {
41514149 Err ( Error :: NoLayoutForOpaqueBlob )
41524150 }
@@ -5610,23 +5608,34 @@ pub(crate) mod utils {
56105608 result. extend ( old_items) ;
56115609 }
56125610
5613- pub ( crate ) fn prepend_opaque_array_type (
5611+ pub ( crate ) fn prepend_opaque_array_types (
56145612 result : & mut Vec < proc_macro2:: TokenStream > ,
56155613 ) {
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+ }
56255635 }
5626- }
5627- } ;
5628-
5629- result. insert ( 0 , ty) ;
5636+ } )
5637+ }
5638+ result. splice ( 0 ..0 , tys) ;
56305639 }
56315640
56325641 pub ( crate ) fn build_path (
0 commit comments