diff options
author | Xidorn Quan <me@upsuper.org> | 2017-07-31 15:09:54 +1000 |
---|---|---|
committer | Xidorn Quan <me@upsuper.org> | 2017-07-31 15:48:54 +1000 |
commit | 90dfdf2af639e45ebc54232c3c79c077b0c86dca (patch) | |
tree | d57bae91eb1f96892a98d617ecb490d4fd0f0209 | |
parent | 3a9a6759ec1d5149fb3a2999f8a05e659b9c02a8 (diff) |
Stablize name of pointer and array
-rw-r--r-- | src/ir/item.rs | 19 | ||||
-rw-r--r-- | tests/expectations/tests/template.rs | 23 | ||||
-rw-r--r-- | tests/headers/template.hpp | 4 |
3 files changed, 38 insertions, 8 deletions
diff --git a/src/ir/item.rs b/src/ir/item.rs index 92954a8f..80e63ffe 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -742,12 +742,21 @@ impl Item { ItemKind::Type(ref ty) => { let name = match *ty.kind() { TypeKind::ResolvedTypeRef(..) => panic!("should have resolved this in name_target()"), - _ => ty.name(), + TypeKind::Pointer(inner) => { + ctx.resolve_item(inner) + .expect_type().name() + .map(|name| format!("ptr_{}", name)) + } + TypeKind::Array(inner, length) => { + ctx.resolve_item(inner) + .expect_type().name() + .map(|name| format!("array_{}_{}", name, length)) + } + _ => ty.name().map(ToOwned::to_owned) }; - name.map(ToOwned::to_owned) - .unwrap_or_else(|| { - format!("_bindgen_ty_{}", self.exposed_id(ctx)) - }) + name.unwrap_or_else(|| { + format!("_bindgen_ty_{}", self.exposed_id(ctx)) + }) } ItemKind::Function(ref fun) => { let mut name = fun.name().to_owned(); diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 8e432167..275f45ea 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -37,6 +37,7 @@ pub struct C { pub mBVolatile: B<::std::os::raw::c_int>, pub mBConstBool: B<bool>, pub mBConstChar: B<u16>, + pub mBArray: B<[::std::os::raw::c_int; 1usize]>, } #[test] fn bindgen_test_layout_C() { @@ -73,6 +74,11 @@ fn bindgen_test_layout_C() { } , 26usize , concat ! ( "Alignment of field: " , stringify ! ( C ) , "::" , stringify ! ( mBConstChar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . mBArray as * const _ as usize } , + 28usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( mBArray ) )); } impl Clone for C { fn clone(&self) -> Self { *self } @@ -317,7 +323,7 @@ fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { B<::std::os::raw::c_uint> ) )); } #[test] -fn __bindgen_test_layout_B_open0__bindgen_ty_id_113_close0_instantiation() { +fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { assert_eq!(::std::mem::size_of::<B<*const ::std::os::raw::c_int>>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -368,6 +374,17 @@ fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { ) )); } #[test] +fn __bindgen_test_layout_B_open0_array_int_1_close0_instantiation() { + assert_eq!(::std::mem::size_of::<B<[::std::os::raw::c_int; 1usize]>>() , + 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + B<[::std::os::raw::c_int; 1usize]> ) )); + assert_eq!(::std::mem::align_of::<B<[::std::os::raw::c_int; 1usize]>>() , + 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + B<[::std::os::raw::c_int; 1usize]> ) )); +} +#[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize , concat ! ( @@ -379,7 +396,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_144_close0_instantiation() { +fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -390,7 +407,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_144_close0_instantiation() Rooted<*mut ::std::os::raw::c_void> ) )); } #[test] -fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_150_close0_instantiation() { +fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp index 7d373152..168eac9c 100644 --- a/tests/headers/template.hpp +++ b/tests/headers/template.hpp @@ -19,6 +19,10 @@ struct C { B<volatile int> mBVolatile; B<const bool> mBConstBool; B<const char16_t> mBConstChar; + B<int[1]> mBArray; + // clang 3.x ignores const in this case, so they generate different + // result than clang 4.0. + // B<const int[1]> mBConstArray; }; template<typename T> |