From 90dfdf2af639e45ebc54232c3c79c077b0c86dca Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 31 Jul 2017 15:09:54 +1000 Subject: [PATCH] Stablize name of pointer and array --- src/ir/item.rs | 19 ++++++++++++++----- tests/expectations/tests/template.rs | 23 ++++++++++++++++++++--- 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 92954a8f10..80e63ffea1 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 8e43216794..275f45eae3 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, pub mBConstChar: B, + 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::>() , 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::>() , + 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + B<[::std::os::raw::c_int; 1usize]> ) )); + assert_eq!(::std::mem::align_of::>() , + 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::>() , 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::>() , 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::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp index 7d373152e9..168eac9c2d 100644 --- a/tests/headers/template.hpp +++ b/tests/headers/template.hpp @@ -19,6 +19,10 @@ struct C { B mBVolatile; B mBConstBool; B mBConstChar; + B mBArray; + // clang 3.x ignores const in this case, so they generate different + // result than clang 4.0. + // B mBConstArray; }; template