diff options
32 files changed, 372 insertions, 176 deletions
diff --git a/src/clang.rs b/src/clang.rs index 5618007b..defdf547 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -17,14 +17,23 @@ pub struct Cursor { impl fmt::Debug for Cursor { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "Cursor({} kind: {}, loc: {})", - self.spelling(), kind_to_str(self.kind()), self.location()) + write!(fmt, "Cursor({} kind: {}, loc: {}, usr: {:?})", + self.spelling(), kind_to_str(self.kind()), self.location(), self.usr()) } } pub type CursorVisitor<'s> = for<'a, 'b> FnMut(&'a Cursor, &'b Cursor) -> Enum_CXChildVisitResult + 's; impl Cursor { + pub fn usr(&self) -> Option<String> { + let s = String_ { x: unsafe { clang_getCursorUSR(self.x) } }.to_string(); + if s.is_empty() { + None + } else { + Some(s) + } + } + pub fn is_declaration(&self) -> bool { unsafe { clang_isDeclaration(self.kind()) != 0 } } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 62cebf46..36f20689 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -311,6 +311,7 @@ impl CodeGenerator for Type { TypeKind::Float(..) | TypeKind::Array(..) | TypeKind::Pointer(..) | + TypeKind::BlockPointer | TypeKind::Reference(..) | TypeKind::TemplateRef(..) | TypeKind::Function(..) | @@ -1306,6 +1307,11 @@ impl ToRustTy for Type { IntKind::ULongLong => raw!(c_ulonglong), IntKind::U16 => aster::ty::TyBuilder::new().u16(), IntKind::U32 => aster::ty::TyBuilder::new().u32(), + // FIXME: This doesn't generate the proper alignment, but we + // can't do better right now. We should be able to use + // i128/u128 when they're available. + IntKind::U128 | + IntKind::I128 => ArrayTyBuilder::new().with_len(2).build(aster::ty::TyBuilder::new().u64()), } } TypeKind::Float(fk) => { @@ -1377,10 +1383,23 @@ impl ToRustTy for Type { utils::build_templated_path(item, ctx, false) } + TypeKind::BlockPointer => { + let void = raw!(c_void); + void.to_ptr(/* is_const = */ false, ctx.span()) + } TypeKind::Pointer(inner) | TypeKind::Reference(inner) => { let inner = ctx.resolve_item(inner); - inner.to_rust_ty(ctx).to_ptr(inner.expect_type().is_const(), ctx.span()) + let inner_ty = inner.expect_type(); + let ty = inner.to_rust_ty(ctx); + + // Avoid the first function pointer level, since it's already + // represented in Rust. + if inner_ty.canonical_type(ctx).is_function() { + ty + } else { + ty.to_ptr(inner.expect_type().is_const(), ctx.span()) + } } TypeKind::Named(..) => { let name = item.canonical_name(ctx); diff --git a/src/ir/context.rs b/src/ir/context.rs index 5ddedda0..559dd2ba 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -14,6 +14,18 @@ use syntax::ext::base::ExtCtxt; use parse::ClangItemParser; use BindgenOptions; +/// A key used to index a resolved type, so we only process it once. +/// +/// This is almost always a USR string (an unique identifier generated by +/// clang), but it can also be the canonical declaration if the type is unnamed, +/// in which case clang may generate the same USR for multiple nested unnamed +/// types. +#[derive(Eq, PartialEq, Hash, Debug)] +enum TypeKey { + USR(String), + Declaration(Cursor), +} + // This is just convenience to avoid creating a manual debug impl for the // context. struct GenContext<'ctx>(ExtCtxt<'ctx>); @@ -33,11 +45,9 @@ pub struct BindgenContext<'ctx> { /// output. items: BTreeMap<ItemId, Item>, - /// Clang cursor to type map. This is needed to be able to associate types - /// with item ids during parsing. - /// - /// The cursor used for storage is the definition cursor. - types: HashMap<Cursor, ItemId>, + /// Clang USR to type map. This is needed to be able to associate types with + /// item ids during parsing. + types: HashMap<TypeKey, ItemId>, /// A cursor to module map. Similar reason than above. modules: HashMap<Cursor, ItemId>, @@ -131,21 +141,25 @@ impl<'ctx> BindgenContext<'ctx> { let id = item.id(); let is_type = item.kind().is_type(); + let is_unnamed = is_type && item.expect_type().name().is_none(); let old_item = self.items.insert(id, item); assert!(old_item.is_none(), "Inserted type twice?"); + // Unnamed items can have an USR, but they can't be referenced from + // other sites explicitly and the USR can match if the unnamed items are + // nested, so don't bother tracking them. if is_type && declaration.is_some() { - let declaration = declaration.unwrap(); - debug_assert_eq!(declaration, declaration.canonical()); - if declaration.is_valid() { - let old = self.types.insert(declaration, id); - debug_assert_eq!(old, None); - } else if location.is_some() && - (location.unwrap().kind() == CXCursor_ClassTemplate || - location.unwrap().kind() == CXCursor_ClassTemplatePartialSpecialization) { - let old = self.types.insert(location.unwrap().canonical(), id); - debug_assert_eq!(old, None); - } else { + let mut declaration = declaration.unwrap(); + if !declaration.is_valid() { + if let Some(location) = location { + if location.kind() == CXCursor_ClassTemplate || + location.kind() == CXCursor_ClassTemplatePartialSpecialization { + declaration = location; + } + } + } + declaration = declaration.canonical(); + if !declaration.is_valid() { // This could happen, for example, with types like `int*` or // similar. // @@ -153,7 +167,20 @@ impl<'ctx> BindgenContext<'ctx> { // duplicated, so we can just ignore them. debug!("Invalid declaration {:?} found for type {:?}", declaration, self.items.get(&id).unwrap().kind().expect_type()); + return; } + + let key = if is_unnamed { + TypeKey::Declaration(declaration) + } else if let Some(usr) = declaration.usr() { + TypeKey::USR(usr) + } else { + error!("Valid declaration with no USR: {:?}, {:?}", declaration, location); + return; + }; + + let old = self.types.insert(key, id); + debug_assert_eq!(old, None); } } @@ -206,7 +233,7 @@ impl<'ctx> BindgenContext<'ctx> { self.collected_typerefs } - fn collect_typerefs(&mut self) -> Vec<(ItemId, clang::Type, Option<clang::Cursor>)> { + fn collect_typerefs(&mut self) -> Vec<(ItemId, clang::Type, Option<clang::Cursor>, Option<ItemId>)> { debug_assert!(!self.collected_typerefs); self.collected_typerefs = true; let mut typerefs = vec![]; @@ -218,8 +245,8 @@ impl<'ctx> BindgenContext<'ctx> { }; match *ty.kind() { - TypeKind::UnresolvedTypeRef(ref ty, loc) => { - typerefs.push((*id, ty.clone(), loc)); + TypeKind::UnresolvedTypeRef(ref ty, loc, parent_id) => { + typerefs.push((*id, ty.clone(), loc, parent_id)); } _ => {}, }; @@ -230,9 +257,9 @@ impl<'ctx> BindgenContext<'ctx> { fn resolve_typerefs(&mut self) { let typerefs = self.collect_typerefs(); - for (id, ty, loc) in typerefs { + for (id, ty, loc, parent_id) in typerefs { let _resolved = { - let resolved = Item::from_ty(&ty, loc, None, self) + let resolved = Item::from_ty(&ty, loc, parent_id, self) .expect("What happened?"); let mut item = self.items.get_mut(&id).unwrap(); @@ -494,8 +521,15 @@ impl<'ctx> BindgenContext<'ctx> { } let canonical_declaration = declaration.canonical(); if canonical_declaration.is_valid() { - // First lookup to see if we already have it resolved. - let id = self.types.get(&canonical_declaration).map(|id| *id); + let id = + self.types.get(&TypeKey::Declaration(canonical_declaration)) + .map(|id| *id) + .or_else(|| { + canonical_declaration.usr().and_then(|usr| { + self.types.get(&TypeKey::USR(usr)) + }) + .map(|id| *id) + }); if let Some(id) = id { debug!("Already resolved ty {:?}, {:?}, {:?} {:?}", id, declaration, ty, location); @@ -572,6 +606,8 @@ impl<'ctx> BindgenContext<'ctx> { CXType_ULong => TypeKind::Int(IntKind::ULong), CXType_LongLong => TypeKind::Int(IntKind::LongLong), CXType_ULongLong => TypeKind::Int(IntKind::ULongLong), + CXType_Int128 => TypeKind::Int(IntKind::I128), + CXType_UInt128 => TypeKind::Int(IntKind::U128), CXType_Float => TypeKind::Float(FloatKind::Float), CXType_Double => TypeKind::Float(FloatKind::Double), CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), diff --git a/src/ir/int.rs b/src/ir/int.rs index d2769b77..75e576d4 100644 --- a/src/ir/int.rs +++ b/src/ir/int.rs @@ -13,6 +13,8 @@ pub enum IntKind { ULongLong, U16, // For Char16 and Wchar U32, // For Char32 + I128, + U128, // Though now we're at it we could add equivalents for the rust types... } @@ -21,10 +23,10 @@ impl IntKind { use self::IntKind::*; match *self { Bool | UChar | UShort | - UInt | ULong | ULongLong | U16 | U32 => false, + UInt | ULong | ULongLong | U16 | U32 | U128 => false, Char | Short | Int | - Long | LongLong => true, + Long | LongLong | I128 => true, } } } diff --git a/src/ir/item.rs b/src/ir/item.rs index c9ac71a4..75c3b857 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -191,10 +191,19 @@ impl Item { TypeKind::Array(inner, _) | TypeKind::Pointer(inner) | TypeKind::Reference(inner) | - TypeKind::Alias(_, inner) | TypeKind::ResolvedTypeRef(inner) => { ctx.resolve_item(inner).applicable_template_args(ctx) } + TypeKind::Alias(_, inner) => { + let parent_args = ctx.resolve_item(self.parent_id()) + .applicable_template_args(ctx); + let inner = ctx.resolve_type(inner); + // Avoid unused type parameters, sigh. + parent_args.iter().cloned().filter(|arg| { + let arg = ctx.resolve_type(*arg); + arg.is_named() && inner.signature_contains_named_type(ctx, arg) + }).collect() + } // XXX Is this completely correct? Partial template specialization // is hard anyways, sigh... TypeKind::TemplateRef(_, ref args) => { @@ -436,11 +445,19 @@ impl ClangItemParser for Item { location: Option<clang::Cursor>, parent_id: Option<ItemId>, context: &mut BindgenContext) -> ItemId { - debug!("from_ty_or_ref: {:?}, {:?}, {:?}", ty, location, parent_id); + Self::from_ty_or_ref_with_id(ItemId::next(), ty, location, parent_id, context) + } + + fn from_ty_or_ref_with_id(potential_id: ItemId, + ty: clang::Type, + location: Option<clang::Cursor>, + parent_id: Option<ItemId>, + context: &mut BindgenContext) -> ItemId { + debug!("from_ty_or_ref_with_id: {:?} {:?}, {:?}, {:?}", potential_id, ty, location, parent_id); if context.collected_typerefs() { debug!("refs already collected, resolving directly"); - return Self::from_ty(&ty, location, parent_id, context) + return Self::from_ty_with_id(potential_id, &ty, location, parent_id, context) .expect("Unable to resolve type"); } @@ -452,15 +469,14 @@ impl ClangItemParser for Item { debug!("New unresolved type reference: {:?}, {:?}", ty, location); let is_const = ty.is_const(); - let kind = TypeKind::UnresolvedTypeRef(ty, location); - let id = ItemId::next(); + let kind = TypeKind::UnresolvedTypeRef(ty, location, parent_id); let current_module = context.current_module(); - context.add_item(Item::new(id, None, None, + context.add_item(Item::new(potential_id, None, None, parent_id.unwrap_or(current_module), ItemKind::Type(Type::new(None, None, kind, is_const))), Some(clang::Cursor::null()), None); - id + potential_id } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index b0448437..97cdf925 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -75,6 +75,13 @@ impl Type { } } + pub fn is_function(&self) -> bool { + match self.kind { + TypeKind::Function(..) => true, + _ => false, + } + } + pub fn is_builtin_or_named(&self) -> bool { match self.kind { TypeKind::Void | @@ -83,6 +90,7 @@ impl Type { TypeKind::Array(..) | TypeKind::Reference(..) | TypeKind::Pointer(..) | + TypeKind::BlockPointer | TypeKind::Int(..) | TypeKind::Float(..) | TypeKind::Named(..) => true, @@ -117,8 +125,9 @@ impl Type { TypeKind::Comp(ref ci) => ci.layout(type_resolver), // FIXME(emilio): This is a hack for anonymous union templates. - // Use the actual pointer size! - TypeKind::Pointer(..) + // Use the actual pointer size! + TypeKind::Pointer(..) | + TypeKind::BlockPointer => Some(Layout::new(mem::size_of::<*mut ()>(), mem::align_of::<*mut ()>())), TypeKind::ResolvedTypeRef(inner) => type_resolver.resolve_type(inner).layout(type_resolver), @@ -243,9 +252,18 @@ impl Type { => this_name == name, TypeKind::ResolvedTypeRef(t) | TypeKind::Array(t, _) | - TypeKind::Pointer(t) + TypeKind::Pointer(t) | + TypeKind::Alias(_, t) => type_resolver.resolve_type(t) .signature_contains_named_type(type_resolver, ty), + TypeKind::Function(ref sig) => { + sig.argument_types().iter().any(|&(_, arg)| { + type_resolver.resolve_type(arg) + .signature_contains_named_type(type_resolver, ty) + }) || + type_resolver.resolve_type(sig.return_type()) + .signature_contains_named_type(type_resolver, ty) + }, TypeKind::TemplateRef(_inner, ref template_args) => { template_args.iter().any(|arg| { type_resolver.resolve_type(*arg) @@ -270,6 +288,7 @@ impl Type { TypeKind::Reference(..) | TypeKind::Void | TypeKind::NullPtr | + TypeKind::BlockPointer | TypeKind::Pointer(..) => self, TypeKind::ResolvedTypeRef(inner) | @@ -318,6 +337,8 @@ pub enum TypeKind { /// A pointer to a type. The bool field represents whether it's const or /// not. Pointer(ItemId), + /// A pointer to an Apple block. + BlockPointer, /// A reference to a type, as in: int& foo(). Reference(ItemId), /// A reference to a template, with different template parameter names. To @@ -332,7 +353,7 @@ pub enum TypeKind { /// already known types, and are converted to ResolvedTypeRef. /// /// see tests/headers/typeref.hpp to see somewhere where this is a problem. - UnresolvedTypeRef(clang::Type, Option<clang::Cursor>), + UnresolvedTypeRef(clang::Type, Option<clang::Cursor>, /* parent_id */ Option<ItemId>), ResolvedTypeRef(ItemId), /// A named type, that is, a template parameter, with an optional default @@ -360,6 +381,7 @@ impl Type { TypeKind::Enum(..) | TypeKind::Reference(..) | TypeKind::NullPtr | + TypeKind::BlockPointer | TypeKind::Pointer(..) => false, TypeKind::UnresolvedTypeRef(..) @@ -427,18 +449,18 @@ impl Type { let referenced = location.referenced(); return Self::from_clang_ty(potential_id, &referenced.cur_type(), - Some(referenced), + Some(referenced.cur_type().declaration()), parent_id, ctx); } CXCursor_TypeRef => { let referenced = location.referenced(); - // FIXME: use potential id? return Ok(ParseResult::AlreadyResolved( - Item::from_ty_or_ref(referenced.cur_type(), - Some(referenced), - parent_id, - ctx))); + Item::from_ty_or_ref_with_id(potential_id, + referenced.cur_type(), + Some(referenced.cur_type().declaration()), + parent_id, + ctx))); } _ => { if ty.kind() == CXType_Unexposed { @@ -471,15 +493,20 @@ impl Type { CXType_MemberPointer | CXType_Pointer => { let inner = - Item::from_ty_or_ref(ty.pointee_type(), Some(ty.pointee_type().declaration()), parent_id, ctx); + Item::from_ty_or_ref(ty.pointee_type(), location, + parent_id, ctx); TypeKind::Pointer(inner) } + CXType_BlockPointer => { + TypeKind::BlockPointer + } // XXX: RValueReference is most likely wrong, but I don't think we // can even add bindings for that, so huh. CXType_RValueReference | CXType_LValueReference => { let inner = - Item::from_ty_or_ref(ty.pointee_type(), Some(ty.pointee_type().declaration()), parent_id, ctx); + Item::from_ty_or_ref(ty.pointee_type(), location, + parent_id, ctx); TypeKind::Reference(inner) } // XXX DependentSizedArray is wrong diff --git a/src/parse.rs b/src/parse.rs index 39d2644a..d6c36aa4 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -29,6 +29,11 @@ pub trait ClangItemParser: Sized { location: Option<clang::Cursor>, parent_id: Option<ItemId>, context: &mut BindgenContext) -> ItemId; + fn from_ty_or_ref_with_id(potential_id: ItemId, + ty: clang::Type, + location: Option<clang::Cursor>, + parent_id: Option<ItemId>, + context: &mut BindgenContext) -> ItemId; fn from_ty_with_id(id: ItemId, ty: &clang::Type, location: Option<clang::Cursor>, diff --git a/tests/expectations/anon_enum.rs b/tests/expectations/anon_enum.rs index 6b8688e1..b06585b1 100644 --- a/tests/expectations/anon_enum.rs +++ b/tests/expectations/anon_enum.rs @@ -12,7 +12,7 @@ pub struct Test { } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Test__bindgen_ty_bindgen_id_4 { T_NONE = 0, } +pub enum Test__bindgen_ty_bindgen_id_6 { T_NONE = 0, } #[test] fn bindgen_test_layout_Test() { assert_eq!(::std::mem::size_of::<Test>() , 8usize); diff --git a/tests/expectations/anon_union.rs b/tests/expectations/anon_union.rs index 66963f40..731d1dd9 100644 --- a/tests/expectations/anon_union.rs +++ b/tests/expectations/anon_union.rs @@ -28,7 +28,7 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy, Clone)] pub struct TErrorResult<T> { pub mResult: ::std::os::raw::c_int, - pub __bindgen_anon_1: TErrorResult__bindgen_ty_bindgen_id_9<T>, + pub __bindgen_anon_1: TErrorResult__bindgen_ty_bindgen_id_10<T>, pub mMightHaveUnreported: bool, pub mUnionState: TErrorResult_UnionState, pub _phantom_0: ::std::marker::PhantomData<T>, @@ -52,7 +52,7 @@ pub struct TErrorResult_DOMExceptionInfo<T> { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct TErrorResult__bindgen_ty_bindgen_id_9<T> { +pub struct TErrorResult__bindgen_ty_bindgen_id_10<T> { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message<T>>, pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo<T>>, pub bindgen_union_field: u64, diff --git a/tests/expectations/blocks.rs b/tests/expectations/blocks.rs new file mode 100644 index 00000000..528ea518 --- /dev/null +++ b/tests/expectations/blocks.rs @@ -0,0 +1,9 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +extern "C" { + pub fn atexit_b(arg1: *mut ::std::os::raw::c_void); +} diff --git a/tests/expectations/class_with_inner_struct.rs b/tests/expectations/class_with_inner_struct.rs index 464c622d..98c0505a 100644 --- a/tests/expectations/class_with_inner_struct.rs +++ b/tests/expectations/class_with_inner_struct.rs @@ -28,8 +28,8 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy)] pub struct A { pub c: ::std::os::raw::c_uint, - pub named_union: A__bindgen_ty_bindgen_id_6, - pub __bindgen_anon_1: A__bindgen_ty_bindgen_id_9, + pub named_union: A__bindgen_ty_bindgen_id_9, + pub __bindgen_anon_1: A__bindgen_ty_bindgen_id_14, } #[repr(C)] #[derive(Debug, Copy)] @@ -47,30 +47,31 @@ impl Clone for A_Segment { } #[repr(C)] #[derive(Debug, Copy)] -pub struct A__bindgen_ty_bindgen_id_6 { +pub struct A__bindgen_ty_bindgen_id_9 { pub f: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } #[test] -fn bindgen_test_layout_A__bindgen_ty_bindgen_id_6() { - assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_6>() , 4usize); - assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_6>() , 4usize); +fn bindgen_test_layout_A__bindgen_ty_bindgen_id_9() { + assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_9>() , 4usize); + assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_9>() , 4usize); } -impl Clone for A__bindgen_ty_bindgen_id_6 { +impl Clone for A__bindgen_ty_bindgen_id_9 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct A__bindgen_ty_bindgen_id_9 { +pub struct A__bindgen_ty_bindgen_id_14 { pub d: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } #[test] -fn bindgen_test_layout_A__bindgen_ty_bindgen_id_9() { - assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_9>() , 4usize); - assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_9>() , 4usize); +fn bindgen_test_layout_A__bindgen_ty_bindgen_id_14() { + assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_14>() , 4usize); + assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_14>() , + 4usize); } -impl Clone for A__bindgen_ty_bindgen_id_9 { +impl Clone for A__bindgen_ty_bindgen_id_14 { fn clone(&self) -> Self { *self } } #[test] @@ -120,57 +121,57 @@ pub enum StepSyntax { #[derive(Debug, Copy)] pub struct C { pub d: ::std::os::raw::c_uint, - pub __bindgen_anon_1: C__bindgen_ty_bindgen_id_21, + pub __bindgen_anon_1: C__bindgen_ty_bindgen_id_31, } #[repr(C)] #[derive(Debug, Copy)] -pub struct C__bindgen_ty_bindgen_id_21 { - pub mFunc: __BindgenUnionField<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22>, - pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28>, +pub struct C__bindgen_ty_bindgen_id_31 { + pub mFunc: __BindgenUnionField<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32>, + pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43>, pub bindgen_union_field: [u32; 4usize], } #[repr(C)] #[derive(Debug, Copy)] -pub struct C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22 { +pub struct C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32 { pub mX1: f32, pub mY1: f32, pub mX2: f32, pub mY2: f32, } #[test] -fn bindgen_test_layout_C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22>() +fn bindgen_test_layout_C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32() { + assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32>() , 16usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22>() + assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32>() , 4usize); } -impl Clone for C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22 { +impl Clone for C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28 { +pub struct C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, } #[test] -fn bindgen_test_layout_C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28>() +fn bindgen_test_layout_C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43() { + assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43>() , 8usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28>() + assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43>() , 4usize); } -impl Clone for C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28 { +impl Clone for C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43 { fn clone(&self) -> Self { *self } } #[test] -fn bindgen_test_layout_C__bindgen_ty_bindgen_id_21() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_21>() , +fn bindgen_test_layout_C__bindgen_ty_bindgen_id_31() { + assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_31>() , 16usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_21>() , + assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_31>() , 4usize); } -impl Clone for C__bindgen_ty_bindgen_id_21 { +impl Clone for C__bindgen_ty_bindgen_id_31 { fn clone(&self) -> Self { *self } } #[repr(C)] diff --git a/tests/expectations/func_ptr.rs b/tests/expectations/func_ptr.rs index c62e532d..87ec3e3d 100644 --- a/tests/expectations/func_ptr.rs +++ b/tests/expectations/func_ptr.rs @@ -7,6 +7,9 @@ extern "C" { #[link_name = "foo"] pub static mut foo: - *mut ::std::option::Option<unsafe extern "C" fn() - -> ::std::os::raw::c_int>; + ::std::option::Option<unsafe extern "C" fn(x: + ::std::os::raw::c_int, + y: + ::std::os::raw::c_int) + -> ::std::os::raw::c_int>; } diff --git a/tests/expectations/func_ptr_in_struct.rs b/tests/expectations/func_ptr_in_struct.rs index 0d4ccdbf..dcae771b 100644 --- a/tests/expectations/func_ptr_in_struct.rs +++ b/tests/expectations/func_ptr_in_struct.rs @@ -9,7 +9,11 @@ pub enum baz { } #[repr(C)] #[derive(Debug, Copy)] pub struct Foo { - pub bar: *mut ::std::option::Option<unsafe extern "C" fn() -> baz>, + pub bar: ::std::option::Option<unsafe extern "C" fn(x: + ::std::os::raw::c_int, + y: + ::std::os::raw::c_int) + -> baz>, } #[test] fn bindgen_test_layout_Foo() { diff --git a/tests/expectations/func_with_func_ptr_arg.rs b/tests/expectations/func_with_func_ptr_arg.rs index b6e345f6..4ac25286 100644 --- a/tests/expectations/func_with_func_ptr_arg.rs +++ b/tests/expectations/func_with_func_ptr_arg.rs @@ -5,5 +5,5 @@ extern "C" { - pub fn foo(bar: *mut ::std::option::Option<unsafe extern "C" fn()>); + pub fn foo(bar: ::std::option::Option<unsafe extern "C" fn()>); } diff --git a/tests/expectations/int128_t.rs b/tests/expectations/int128_t.rs new file mode 100644 index 00000000..b4b7b2bc --- /dev/null +++ b/tests/expectations/int128_t.rs @@ -0,0 +1,7 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + + diff --git a/tests/expectations/jsval_layout_opaque.rs b/tests/expectations/jsval_layout_opaque.rs index 69fe54dc..dd432232 100644 --- a/tests/expectations/jsval_layout_opaque.rs +++ b/tests/expectations/jsval_layout_opaque.rs @@ -93,8 +93,8 @@ pub enum JSWhyMagic { #[derive(Debug, Copy)] pub struct jsval_layout { pub asBits: __BindgenUnionField<u64>, - pub debugView: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_81>, - pub s: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_85>, + pub debugView: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_89>, + pub s: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_96>, pub asDouble: __BindgenUnionField<f64>, pub asPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub asWord: __BindgenUnionField<usize>, @@ -103,20 +103,20 @@ pub struct jsval_layout { } #[repr(C)] #[derive(Debug, Copy)] -pub struct jsval_layout__bindgen_ty_bindgen_id_81 { +pub struct jsval_layout__bindgen_ty_bindgen_id_89 { pub _bitfield_1: u64, } #[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_81() { - assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_81>() +fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_89() { + assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_89>() , 8usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_81>() + assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_89>() , 8usize); } -impl Clone for jsval_layout__bindgen_ty_bindgen_id_81 { +impl Clone for jsval_layout__bindgen_ty_bindgen_id_89 { fn clone(&self) -> Self { *self } } -impl jsval_layout__bindgen_ty_bindgen_id_81 { +impl jsval_layout__bindgen_ty_bindgen_id_89 { #[inline] pub fn payload47(&self) -> u64 { unsafe { @@ -149,36 +149,36 @@ impl jsval_layout__bindgen_ty_bindgen_id_81 { } #[repr(C)] #[derive(Debug, Copy)] -pub struct jsval_layout__bindgen_ty_bindgen_id_85 { - pub payload: jsval_layout__bindgen_ty_bindgen_id_85__bindgen_ty_bindgen_id_86, +pub struct jsval_layout__bindgen_ty_bindgen_id_96 { + pub payload: jsval_layout__bindgen_ty_bindgen_id_96__bindgen_ty_bindgen_id_97, } #[repr(C)] #[derive(Debug, Copy)] -pub struct jsval_layout__bindgen_ty_bindgen_id_85__bindgen_ty_bindgen_id_86 { +pub struct jsval_layout__bindgen_ty_bindgen_id_96__bindgen_ty_bindgen_id_97 { pub i32: __BindgenUnionField<i32>, pub u32: __BindgenUnionField<u32>, pub why: __BindgenUnionField<JSWhyMagic>, pub bindgen_union_field: u32, } #[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_85__bindgen_ty_bindgen_id_86() { - assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_85__bindgen_ty_bindgen_id_86>() +fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_96__bindgen_ty_bindgen_id_97() { + assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_96__bindgen_ty_bindgen_id_97>() , 4usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_85__bindgen_ty_bindgen_id_86>() + assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_96__bindgen_ty_bindgen_id_97>() , 4usize); } impl Clone for - jsval_layout__bindgen_ty_bindgen_id_85__bindgen_ty_bindgen_id_86 { + jsval_layout__bindgen_ty_bindgen_id_96__bindgen_ty_bindgen_id_97 { fn clone(&self) -> Self { *self } } #[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_85() { - assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_85>() +fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_96() { + assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_96>() , 4usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_85>() + assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_96>() , 4usize); } -impl Clone for jsval_layout__bindgen_ty_bindgen_id_85 { +impl Clone for jsval_layout__bindgen_ty_bindgen_id_96 { fn clone(&self) -> Self { *self } } impl Clone for jsval_layout { diff --git a/tests/expectations/namespace.rs b/tests/expectations/namespace.rs index 0bd6e8e0..ed0ca603 100644 --- a/tests/expectations/namespace.rs +++ b/tests/expectations/namespace.rs @@ -18,7 +18,7 @@ pub mod root { pub fn in_whatever(); } } - pub mod _bindgen_mod_bindgen_id_12 { + pub mod _bindgen_mod_bindgen_id_13 { use root; pub mod empty { use root; @@ -44,7 +44,7 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct C<T> { - pub _base: root::_bindgen_mod_bindgen_id_12::A, + pub _base: root::_bindgen_mod_bindgen_id_13::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], @@ -78,7 +78,7 @@ extern "C" { #[repr(C)] #[derive(Debug)] pub struct C<T> { - pub _base: root::_bindgen_mod_bindgen_id_12::A, + pub _base: root::_bindgen_mod_bindgen_id_13::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], diff --git a/tests/expectations/struct_with_anon_struct_array.rs b/tests/expectations/struct_with_anon_struct_array.rs index 48cc71d2..c87605de 100644 --- a/tests/expectations/struct_with_anon_struct_array.rs +++ b/tests/expectations/struct_with_anon_struct_array.rs @@ -8,7 +8,7 @@ #[derive(Debug, Copy)] pub struct foo { pub bar: [foo__bindgen_ty_bindgen_id_2; 2usize], - pub baz: [[[foo__bindgen_ty_bindgen_id_6; 4usize]; 3usize]; 2usize], + pub baz: [[[foo__bindgen_ty_bindgen_id_8; 4usize]; 3usize]; 2usize], } #[repr(C)] #[derive(Debug, Copy)] @@ -28,18 +28,18 @@ impl Clone for foo__bindgen_ty_bindgen_id_2 { } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_6 { +pub struct foo__bindgen_ty_bindgen_id_8 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_6() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_6>() , +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_8() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_8>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_6>() , + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_8>() , 4usize); } -impl Clone for foo__bindgen_ty_bindgen_id_6 { +impl Clone for foo__bindgen_ty_bindgen_id_8 { fn clone(&self) -> Self { *self } } #[test] diff --git a/tests/expectations/struct_with_nesting.rs b/tests/expectations/struct_with_nesting.rs index ca5ec09e..9eeeb56e 100644 --- a/tests/expectations/struct_with_nesting.rs +++ b/tests/expectations/struct_with_nesting.rs @@ -28,58 +28,58 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy)] pub struct foo { pub a: ::std::os::raw::c_uint, - pub __bindgen_anon_1: foo__bindgen_ty_bindgen_id_3, + pub __bindgen_anon_1: foo__bindgen_ty_bindgen_id_4, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3 { +pub struct foo__bindgen_ty_bindgen_id_4 { pub b: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_5>, - pub __bindgen_anon_2: __BindgenUnionField<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_8>, + pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_7>, + pub __bindgen_anon_2: __BindgenUnionField<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_12>, pub bindgen_union_field: u32, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_5 { +pub struct foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_7 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_5() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_5>() +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_7() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_7>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_5>() + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_7>() , 2usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_5 { +impl Clone for foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_7 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_8 { +pub struct foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_12 { pub d1: ::std::os::raw::c_uchar, pub d2: ::std::os::raw::c_uchar, pub d3: ::std::os::raw::c_uchar, pub d4: ::std::os::raw::c_uchar, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_8() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_8>() +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_12() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_12>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_8>() + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_12>() , 1usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_8 { +impl Clone for foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_12 { fn clone(&self) -> Self { *self } } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3>() , +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3>() , + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4>() , 4usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3 { +impl Clone for foo__bindgen_ty_bindgen_id_4 { fn clone(&self) -> Self { *self } } #[test] diff --git a/tests/expectations/struct_with_typedef_template_arg.rs b/tests/expectations/struct_with_typedef_template_arg.rs new file mode 100644 index 00000000..6f8d71f1 --- /dev/null +++ b/tests/expectations/struct_with_typedef_template_arg.rs @@ -0,0 +1,15 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Proxy<T, Args> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, + pub _phantom_1: ::std::marker::PhantomData<Args>, +} +pub type Proxy_foo<T> = + ::std::option::Option<unsafe extern "C" fn(bar: *mut T)>; diff --git a/tests/expectations/template_typedefs.rs b/tests/expectations/template_typedefs.rs new file mode 100644 index 00000000..5f0d80b9 --- /dev/null +++ b/tests/expectations/template_typedefs.rs @@ -0,0 +1,22 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub type foo = + ::std::option::Option<unsafe extern "C" fn(arg1: ::std::os::raw::c_int)>; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo<T, U> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, + pub _phantom_1: ::std::marker::PhantomData<U>, +} +pub type Foo_Char<T> = T; +pub type Foo_FooPtrTypedef<T> = *mut Foo_Char<T>; +pub type Foo_nsCOMArrayEnumFunc<T> = + ::std::option::Option<unsafe extern "C" fn(aElement: *mut T, + aData: + *mut ::std::os::raw::c_void) + -> bool>; diff --git a/tests/expectations/typeref.rs b/tests/expectations/typeref.rs index 35a873c9..50795077 100644 --- a/tests/expectations/typeref.rs +++ b/tests/expectations/typeref.rs @@ -79,12 +79,12 @@ impl Clone for Bar { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleShapeSource<ReferenceBox> { - pub __bindgen_anon_1: StyleShapeSource__bindgen_ty_bindgen_id_13<ReferenceBox>, + pub __bindgen_anon_1: StyleShapeSource__bindgen_ty_bindgen_id_14<ReferenceBox>, pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct StyleShapeSource__bindgen_ty_bindgen_id_13<ReferenceBox> { +pub struct StyleShapeSource__bindgen_ty_bindgen_id_14<ReferenceBox> { pub mPosition: __BindgenUnionField<*mut Position>, pub mFragmentOrURL: __BindgenUnionField<*mut FragmentOrURL>, pub bindgen_union_field: u64, diff --git a/tests/expectations/union_template.rs b/tests/expectations/union_template.rs index f07087de..1e3cf17e 100644 --- a/tests/expectations/union_template.rs +++ b/tests/expectations/union_template.rs @@ -28,13 +28,13 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy, Clone)] pub struct NastyStruct<T> { pub mIsSome: bool, - pub mStorage: NastyStruct__bindgen_ty_bindgen_id_5<T>, - pub __bindgen_anon_1: NastyStruct__bindgen_ty_bindgen_id_9<T>, + pub mStorage: NastyStruct__bindgen_ty_bindgen_id_6<T>, + pub __bindgen_anon_1: NastyStruct__bindgen_ty_bindgen_id_12<T>, pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct NastyStruct__bindgen_ty_bindgen_id_5<T> { +pub struct NastyStruct__bindgen_ty_bindgen_id_6<T> { pub mFoo: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mDummy: __BindgenUnionField<::std::os::raw::c_ulong>, pub bindgen_union_field: u64, @@ -42,7 +42,7 @@ pub struct NastyStruct__bindgen_ty_bindgen_id_5<T> { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct NastyStruct__bindgen_ty_bindgen_id_9<T> { +pub struct NastyStruct__bindgen_ty_bindgen_id_12<T> { pub wat: __BindgenUnionField<::std::os::raw::c_short>, pub wut: __BindgenUnionField<*mut ::std::os::raw::c_int>, pub bindgen_union_field: u64, diff --git a/tests/expectations/union_with_anon_struct_bitfield.rs b/tests/expectations/union_with_anon_struct_bitfield.rs index 80be0e55..1332d92e 100644 --- a/tests/expectations/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/union_with_anon_struct_bitfield.rs @@ -28,25 +28,25 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_int>, - pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_3>, + pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_4>, pub bindgen_union_field: u32, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3 { +pub struct foo__bindgen_ty_bindgen_id_4 { pub _bitfield_1: u32, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3>() , +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3>() , + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4>() , 4usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3 { +impl Clone for foo__bindgen_ty_bindgen_id_4 { fn clone(&self) -> Self { *self } } -impl foo__bindgen_ty_bindgen_id_3 { +impl foo__bindgen_ty_bindgen_id_4 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { unsafe { diff --git a/tests/expectations/union_with_anon_unnamed_struct.rs b/tests/expectations/union_with_anon_unnamed_struct.rs index 80b3e97a..defbe66b 100644 --- a/tests/expectations/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/union_with_anon_unnamed_struct.rs @@ -28,25 +28,25 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy)] pub struct pixel { pub rgba: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField<pixel__bindgen_ty_bindgen_id_3>, + pub __bindgen_anon_1: __BindgenUnionField<pixel__bindgen_ty_bindgen_id_4>, pub bindgen_union_field: u32, } #[repr(C)] #[derive(Debug, Copy)] -pub struct pixel__bindgen_ty_bindgen_id_3 { +pub struct pixel__bindgen_ty_bindgen_id_4 { pub r: ::std::os::raw::c_uchar, pub g: ::std::os::raw::c_uchar, pub b: ::std::os::raw::c_uchar, pub a: ::std::os::raw::c_uchar, } #[test] -fn bindgen_test_layout_pixel__bindgen_ty_bindgen_id_3() { - assert_eq!(::std::mem::size_of::<pixel__bindgen_ty_bindgen_id_3>() , +fn bindgen_test_layout_pixel__bindgen_ty_bindgen_id_4() { + assert_eq!(::std::mem::size_of::<pixel__bindgen_ty_bindgen_id_4>() , 4usize); - assert_eq!(::std::mem::align_of::<pixel__bindgen_ty_bindgen_id_3>() , + assert_eq!(::std::mem::align_of::<pixel__bindgen_ty_bindgen_id_4>() , 1usize); } -impl Clone for pixel__bindgen_ty_bindgen_id_3 { +impl Clone for pixel__bindgen_ty_bindgen_id_4 { fn clone(&self) -> Self { *self } } #[test] diff --git a/tests/expectations/union_with_anon_unnamed_union.rs b/tests/expectations/union_with_anon_unnamed_union.rs index 3ddea69e..519bf619 100644 --- a/tests/expectations/union_with_anon_unnamed_union.rs +++ b/tests/expectations/union_with_anon_unnamed_union.rs @@ -28,24 +28,24 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_3>, + pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_4>, pub bindgen_union_field: u32, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3 { +pub struct foo__bindgen_ty_bindgen_id_4 { pub b: __BindgenUnionField<::std::os::raw::c_ushort>, pub c: __BindgenUnionField<::std::os::raw::c_uchar>, pub bindgen_union_field: u16, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3>() , +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4>() , 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3>() , + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4>() , 2usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3 { +impl Clone for foo__bindgen_ty_bindgen_id_4 { fn clone(&self) -> Self { *self } } #[test] diff --git a/tests/expectations/union_with_nesting.rs b/tests/expectations/union_with_nesting.rs index 6b8d318d..d7fc780a 100644 --- a/tests/expectations/union_with_nesting.rs +++ b/tests/expectations/union_with_nesting.rs @@ -28,57 +28,57 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } #[derive(Debug, Copy)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_3>, + pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_bindgen_id_4>, pub bindgen_union_field: u32, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3 { - pub __bindgen_anon_1: foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_4, - pub __bindgen_anon_2: foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_7, +pub struct foo__bindgen_ty_bindgen_id_4 { + pub __bindgen_anon_1: foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_5, + pub __bindgen_anon_2: foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_10, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_4 { +pub struct foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_5 { pub b1: __BindgenUnionField<::std::os::raw::c_ushort>, pub b2: __BindgenUnionField<::std::os::raw::c_ushort>, pub bindgen_union_field: u16, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_4() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_4>() +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_5() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_5>() , 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_4>() + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_5>() , 2usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_4 { +impl Clone for foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_5 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_7 { +pub struct foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_10 { pub c1: __BindgenUnionField<::std::os::raw::c_ushort>, pub c2: __BindgenUnionField<::std::os::raw::c_ushort>, pub bindgen_union_field: u16, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_7() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_7>() +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_10() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_10>() , 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_7>() + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_10>() , 2usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3__bindgen_ty_bindgen_id_7 { +impl Clone for foo__bindgen_ty_bindgen_id_4__bindgen_ty_bindgen_id_10 { fn clone(&self) -> Self { *self } } #[test] -fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_3() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_3>() , +fn bindgen_test_layout_foo__bindgen_ty_bindgen_id_4() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_bindgen_id_4>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_3>() , + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_bindgen_id_4>() , 2usize); } -impl Clone for foo__bindgen_ty_bindgen_id_3 { +impl Clone for foo__bindgen_ty_bindgen_id_4 { fn clone(&self) -> Self { *self } } #[test] diff --git a/tests/expectations/what_is_going_on.rs b/tests/expectations/what_is_going_on.rs index b6a5c86a..6f1998d1 100644 --- a/tests/expectations/what_is_going_on.rs +++ b/tests/expectations/what_is_going_on.rs @@ -21,9 +21,8 @@ pub type Float = f32; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct PointTyped<units, F> { - pub x: Float, - pub y: Float, + pub x: F, + pub y: F, pub _phantom_0: ::std::marker::PhantomData<units>, - pub _phantom_1: ::std::marker::PhantomData<F>, } pub type IntPoint = PointTyped<UnknownUnits, f32>; diff --git a/tests/headers/blocks.h b/tests/headers/blocks.h new file mode 100644 index 00000000..80420e6e --- /dev/null +++ b/tests/headers/blocks.h @@ -0,0 +1,3 @@ +// bindgen-flags: -- -fblocks + +void atexit_b(void (^)(void)); diff --git a/tests/headers/int128_t.h b/tests/headers/int128_t.h new file mode 100644 index 00000000..eece252c --- /dev/null +++ b/tests/headers/int128_t.h @@ -0,0 +1,7 @@ +/** + * FIXME: Uncomment this once we can generate the proper alignment for the type, + * i.e., when we use u128/i128. +struct Foo { + __int128 foo; +}; + */ diff --git a/tests/headers/struct_with_typedef_template_arg.hpp b/tests/headers/struct_with_typedef_template_arg.hpp new file mode 100644 index 00000000..7fed21ab --- /dev/null +++ b/tests/headers/struct_with_typedef_template_arg.hpp @@ -0,0 +1,4 @@ +template<typename T, typename ...Args> +struct Proxy { + typedef void (*foo)(T* bar); +}; diff --git a/tests/headers/template_typedefs.hpp b/tests/headers/template_typedefs.hpp new file mode 100644 index 00000000..5e13dcd8 --- /dev/null +++ b/tests/headers/template_typedefs.hpp @@ -0,0 +1,8 @@ +typedef void (*foo)(int); + +template<typename T, typename U> +class Foo { + typedef T Char; + typedef Char* FooPtrTypedef; + typedef bool (*nsCOMArrayEnumFunc)(T* aElement, void* aData); +}; |