Skip to content

Commit 8b81011

Browse files
author
bors-servo
authored
Auto merge of #872 - upsuper:ptr-array-name, r=emilio
Stablize name of pointer and array This fixes #871.
2 parents 3a9a675 + 90dfdf2 commit 8b81011

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/ir/item.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,21 @@ impl Item {
742742
ItemKind::Type(ref ty) => {
743743
let name = match *ty.kind() {
744744
TypeKind::ResolvedTypeRef(..) => panic!("should have resolved this in name_target()"),
745-
_ => ty.name(),
745+
TypeKind::Pointer(inner) => {
746+
ctx.resolve_item(inner)
747+
.expect_type().name()
748+
.map(|name| format!("ptr_{}", name))
749+
}
750+
TypeKind::Array(inner, length) => {
751+
ctx.resolve_item(inner)
752+
.expect_type().name()
753+
.map(|name| format!("array_{}_{}", name, length))
754+
}
755+
_ => ty.name().map(ToOwned::to_owned)
746756
};
747-
name.map(ToOwned::to_owned)
748-
.unwrap_or_else(|| {
749-
format!("_bindgen_ty_{}", self.exposed_id(ctx))
750-
})
757+
name.unwrap_or_else(|| {
758+
format!("_bindgen_ty_{}", self.exposed_id(ctx))
759+
})
751760
}
752761
ItemKind::Function(ref fun) => {
753762
let mut name = fun.name().to_owned();

tests/expectations/tests/template.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct C {
3737
pub mBVolatile: B<::std::os::raw::c_int>,
3838
pub mBConstBool: B<bool>,
3939
pub mBConstChar: B<u16>,
40+
pub mBArray: B<[::std::os::raw::c_int; 1usize]>,
4041
}
4142
#[test]
4243
fn bindgen_test_layout_C() {
@@ -73,6 +74,11 @@ fn bindgen_test_layout_C() {
7374
} , 26usize , concat ! (
7475
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
7576
! ( mBConstChar ) ));
77+
assert_eq! (unsafe {
78+
& ( * ( 0 as * const C ) ) . mBArray as * const _ as usize } ,
79+
28usize , concat ! (
80+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
81+
! ( mBArray ) ));
7682
}
7783
impl Clone for C {
7884
fn clone(&self) -> Self { *self }
@@ -317,7 +323,7 @@ fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() {
317323
B<::std::os::raw::c_uint> ) ));
318324
}
319325
#[test]
320-
fn __bindgen_test_layout_B_open0__bindgen_ty_id_113_close0_instantiation() {
326+
fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() {
321327
assert_eq!(::std::mem::size_of::<B<*const ::std::os::raw::c_int>>() ,
322328
8usize , concat ! (
323329
"Size of template specialization: " , stringify ! (
@@ -368,6 +374,17 @@ fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() {
368374
) ));
369375
}
370376
#[test]
377+
fn __bindgen_test_layout_B_open0_array_int_1_close0_instantiation() {
378+
assert_eq!(::std::mem::size_of::<B<[::std::os::raw::c_int; 1usize]>>() ,
379+
4usize , concat ! (
380+
"Size of template specialization: " , stringify ! (
381+
B<[::std::os::raw::c_int; 1usize]> ) ));
382+
assert_eq!(::std::mem::align_of::<B<[::std::os::raw::c_int; 1usize]>>() ,
383+
4usize , concat ! (
384+
"Alignment of template specialization: " , stringify ! (
385+
B<[::std::os::raw::c_int; 1usize]> ) ));
386+
}
387+
#[test]
371388
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
372389
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
373390
concat ! (
@@ -379,7 +396,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
379396
Foo<::std::os::raw::c_int> ) ));
380397
}
381398
#[test]
382-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_144_close0_instantiation() {
399+
fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() {
383400
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
384401
24usize , concat ! (
385402
"Size of template specialization: " , stringify ! (
@@ -390,7 +407,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_144_close0_instantiation()
390407
Rooted<*mut ::std::os::raw::c_void> ) ));
391408
}
392409
#[test]
393-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_150_close0_instantiation() {
410+
fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() {
394411
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
395412
24usize , concat ! (
396413
"Size of template specialization: " , stringify ! (

tests/headers/template.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ struct C {
1919
B<volatile int> mBVolatile;
2020
B<const bool> mBConstBool;
2121
B<const char16_t> mBConstChar;
22+
B<int[1]> mBArray;
23+
// clang 3.x ignores const in this case, so they generate different
24+
// result than clang 4.0.
25+
// B<const int[1]> mBConstArray;
2226
};
2327

2428
template<typename T>

0 commit comments

Comments
 (0)