diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-09-19 03:04:47 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-09-19 03:05:12 +0200 |
commit | 7455e3b5b98c392bd4c313b851cda2857581ed8f (patch) | |
tree | 8eb313679d1c0fb66c5abaceb43a137e8ae03c6c /src/codegen | |
parent | 9087c2f065c8ae868ad418afee0c4bc5921337e6 (diff) |
Teach the blob code to generate i128 / u128 if available.
This is very mechanical and boring, but needed.
Diffstat (limited to 'src/codegen')
-rw-r--r-- | src/codegen/helpers.rs | 10 | ||||
-rw-r--r-- | src/codegen/impl_debug.rs | 2 | ||||
-rw-r--r-- | src/codegen/mod.rs | 20 | ||||
-rw-r--r-- | src/codegen/struct_layout.rs | 2 |
4 files changed, 17 insertions, 17 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index b7c3df7f..55430fe9 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -59,14 +59,14 @@ pub mod attributes { /// Generates a proper type for a field or type with a given `Layout`, that is, /// a type with the correct size and alignment restrictions. -pub fn blob(layout: Layout) -> quote::Tokens { +pub fn blob(ctx: &BindgenContext, layout: Layout) -> quote::Tokens { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are // some things that legitimately are more than 8-byte aligned. // // Eventually we should be able to `unwrap` here, but... - let ty_name = match opaque.known_rust_type_for_array() { + let ty_name = match opaque.known_rust_type_for_array(ctx) { Some(ty) => ty, None => { warn!("Found unknown alignment on code generation!"); @@ -76,7 +76,7 @@ pub fn blob(layout: Layout) -> quote::Tokens { let ty_name = Term::new(ty_name, Span::call_site()); - let data_len = opaque.array_size().unwrap_or(layout.size); + let data_len = opaque.array_size(ctx).unwrap_or(layout.size); if data_len == 1 { quote! { @@ -90,8 +90,8 @@ pub fn blob(layout: Layout) -> quote::Tokens { } /// Integer type of the same size as the given `Layout`. -pub fn integer_type(layout: Layout) -> Option<quote::Tokens> { - let name = Layout::known_type_for_size(layout.size)?; +pub fn integer_type(ctx: &BindgenContext, layout: Layout) -> Option<quote::Tokens> { + let name = Layout::known_type_for_size(ctx, layout.size)?; let name = Term::new(name, Span::call_site()); Some(quote! { #name }) } diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs index 0f8e4d96..2c6d36d9 100644 --- a/src/codegen/impl_debug.rs +++ b/src/codegen/impl_debug.rs @@ -236,7 +236,7 @@ impl<'a> ImplDebug<'a> for Item { let inner_type = ctx.resolve_type(inner).canonical_type(ctx); match *inner_type.kind() { TypeKind::Function(ref sig) - if !sig.can_trivially_derive_debug() => { + if !sig.can_trivially_derive_debug(ctx) => { Some((format!("{}: FunctionPointer", name), vec![])) } _ => debug_print(name, quote! { #name_ident }), diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 86a29c50..b5188916 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1185,7 +1185,7 @@ impl Bitfield { let bitfield_ty_layout = bitfield_ty.layout(ctx).expect( "Bitfield without layout? Gah!", ); - let bitfield_int_ty = helpers::blob(bitfield_ty_layout); + let bitfield_int_ty = helpers::blob(ctx, bitfield_ty_layout); let offset = self.offset_into_unit(); let width = self.width() as u8; @@ -1367,7 +1367,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { let bitfield_ty_layout = bitfield_ty.layout(ctx).expect( "Bitfield without layout? Gah!", ); - let bitfield_int_ty = match helpers::integer_type(bitfield_ty_layout) { + let bitfield_int_ty = match helpers::integer_type(ctx, bitfield_ty_layout) { Some(int_ty) => { *bitfield_representable_as_int = true; int_ty @@ -1547,7 +1547,7 @@ impl CodeGenerator for CompInfo { } let layout = layout.expect("Unable to get layout information?"); - let ty = helpers::blob(layout); + let ty = helpers::blob(ctx, layout); fields.push(if self.can_be_rust_union(ctx) { quote! { @@ -1572,7 +1572,7 @@ impl CodeGenerator for CompInfo { Some(l) => { explicit_align = Some(l.align); - let ty = helpers::blob(l); + let ty = helpers::blob(ctx, l); fields.push(quote! { pub _bindgen_opaque_blob: #ty , }); @@ -1595,7 +1595,7 @@ impl CodeGenerator for CompInfo { } else { explicit_align = Some(layout.align); if !ctx.options().rust_features.repr_align { - let ty = helpers::blob(Layout::new(0, layout.align)); + let ty = helpers::blob(ctx, Layout::new(0, layout.align)); fields.push(quote! { pub __bindgen_align: #ty , }); @@ -1629,7 +1629,7 @@ impl CodeGenerator for CompInfo { }; if has_address { - let ty = helpers::blob(Layout::new(1, 1)); + let ty = helpers::blob(ctx, Layout::new(1, 1)); fields.push(quote! { pub _address: #ty, }); @@ -2800,7 +2800,7 @@ trait TryToOpaque { extra: &Self::Extra, ) -> error::Result<quote::Tokens> { self.try_get_layout(ctx, extra).map(|layout| { - helpers::blob(layout) + helpers::blob(ctx, layout) }) } } @@ -2827,7 +2827,7 @@ trait ToOpaque: TryToOpaque { extra: &Self::Extra, ) -> quote::Tokens { let layout = self.get_layout(ctx, extra); - helpers::blob(layout) + helpers::blob(ctx, layout) } } @@ -2885,7 +2885,7 @@ where |_| if let Ok(layout) = self.try_get_layout(ctx, extra) { - Ok(helpers::blob(layout)) + Ok(helpers::blob(ctx, layout)) } else { Err(error::Error::NoLayoutForOpaqueBlob) }, @@ -3037,7 +3037,7 @@ impl TryToRustTy for Type { IntKind::LongLong => Ok(raw_type(ctx, "c_longlong")), IntKind::ULongLong => Ok(raw_type(ctx, "c_ulonglong")), IntKind::WChar { size } => { - let ty = Layout::known_type_for_size(size) + let ty = Layout::known_type_for_size(ctx, size) .expect("Non-representable wchar_t?"); let ident = ctx.rust_ident_raw(ty); Ok(quote! { #ident }) diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 6de7e030..b70fb658 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -306,7 +306,7 @@ impl<'a> StructLayoutTracker<'a> { } fn padding_field(&mut self, layout: Layout) -> quote::Tokens { - let ty = helpers::blob(layout); + let ty = helpers::blob(self.ctx, layout); let padding_count = self.padding_count; self.padding_count += 1; |