diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 78274d94fb..41fac5421d 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -86,6 +86,24 @@ impl Type { /// Get this type's name. pub fn name(&self) -> Option<&str> { + if let TypeKind::Int(ik) = *self.kind() { + // these types will return spaces in their names + // unless we manually change it + match ik { + IntKind::Char { .. } => return Some("char"), + IntKind::SChar => return Some("signed_char"), + IntKind::UChar => return Some("unsigned_char"), + IntKind::Short => return Some("short"), + IntKind::UShort => return Some("unsigned_short"), + IntKind::Int => return Some("int"), + IntKind::UInt => return Some("unsigned_int"), + IntKind::Long => return Some("long"), + IntKind::ULong => return Some("unsigned_long"), + IntKind::LongLong => return Some("longlong"), + IntKind::ULongLong => return Some("unsigned_longlong"), + _ => () + } + } self.name.as_ref().map(|name| &**name) } diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 8fe4941ba5..f89db6fff9 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -15,11 +15,60 @@ pub struct Foo { impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct B { + pub m_member: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for B { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} extern "C" { #[link_name = "_Z3bar3FooIiiE"] pub fn bar(foo: Foo<::std::os::raw::c_int>); } #[repr(C)] +#[derive(Debug, Copy)] +pub struct C { + pub mB: B<::std::os::raw::c_uint>, + pub mBConstPtr: B<*const ::std::os::raw::c_int>, + pub mBConst: B<::std::os::raw::c_int>, + pub mBVolatile: B<::std::os::raw::c_int>, +} +#[test] +fn bindgen_test_layout_C() { + assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . mB as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( mB ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . mBConstPtr as * const _ as usize + } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( mBConstPtr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . mBConst as * const _ as usize } , + 16usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( mBConst ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . mBVolatile as * const _ as usize + } , 20usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( mBVolatile ) )); +} +impl Clone for C { + fn clone(&self) -> Self { *self } +} +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[repr(C)] #[derive(Debug)] pub struct D { pub m_foo: D_MyFoo, @@ -245,6 +294,50 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { Foo<::std::os::raw::c_int> ) )); } #[test] +fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { + assert_eq!(::std::mem::size_of::>() , 4usize , + concat ! ( + "Size of template specialization: " , stringify ! ( + B<::std::os::raw::c_uint> ) )); + assert_eq!(::std::mem::align_of::>() , 4usize , + concat ! ( + "Alignment of template specialization: " , stringify ! ( + B<::std::os::raw::c_uint> ) )); +} +#[test] +fn __bindgen_test_layout_B_open0__bindgen_ty_id_111_close0_instantiation() { + assert_eq!(::std::mem::size_of::>() , + 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + B<*const ::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::>() , + 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + B<*const ::std::os::raw::c_int> ) )); +} +#[test] +fn __bindgen_test_layout_B_open0_int_close0_instantiation() { + assert_eq!(::std::mem::size_of::>() , 4usize , + concat ! ( + "Size of template specialization: " , stringify ! ( + B<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::>() , 4usize , + concat ! ( + "Alignment of template specialization: " , stringify ! ( + B<::std::os::raw::c_int> ) )); +} +#[test] +fn __bindgen_test_layout_B_open0_int_close0_instantiation_1() { + assert_eq!(::std::mem::size_of::>() , 4usize , + concat ! ( + "Size of template specialization: " , stringify ! ( + B<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::>() , 4usize , + concat ! ( + "Alignment of template specialization: " , stringify ! ( + B<::std::os::raw::c_int> ) )); +} +#[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( @@ -256,7 +349,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { Foo<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() { +fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_134_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -267,7 +360,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() Rooted<*mut ::std::os::raw::c_void> ) )); } #[test] -fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation() { +fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_140_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp index 29a0792bb9..57a137974e 100644 --- a/tests/headers/template.hpp +++ b/tests/headers/template.hpp @@ -4,8 +4,19 @@ template class Foo { T m_member_arr[1]; }; +template class B { + T m_member; +}; + void bar(Foo foo); +struct C { + B mB; + B mBConstPtr; + B mBConst; + B mBVolatile; +}; + template class D { typedef Foo MyFoo;