Skip to content

Stablize name of pointer and array #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 20 additions & 3 deletions tests/expectations/tests/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 ! (
Expand Down Expand Up @@ -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 ! (
Expand All @@ -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 ! (
Expand All @@ -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 ! (
Expand Down
4 changes: 4 additions & 0 deletions tests/headers/template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down