Skip to content

Commit 5b1b73a

Browse files
committed
Stablize name of pointer and array
1 parent 3a9a675 commit 5b1b73a

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
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: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ 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]>,
41+
pub mBConstArray: B<[::std::os::raw::c_int; 1usize]>,
4042
}
4143
#[test]
4244
fn bindgen_test_layout_C() {
43-
assert_eq!(::std::mem::size_of::<C>() , 32usize , concat ! (
45+
assert_eq!(::std::mem::size_of::<C>() , 40usize , concat ! (
4446
"Size of: " , stringify ! ( C ) ));
4547
assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
4648
"Alignment of " , stringify ! ( C ) ));
@@ -73,6 +75,16 @@ fn bindgen_test_layout_C() {
7375
} , 26usize , concat ! (
7476
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
7577
! ( mBConstChar ) ));
78+
assert_eq! (unsafe {
79+
& ( * ( 0 as * const C ) ) . mBArray as * const _ as usize } ,
80+
28usize , concat ! (
81+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
82+
! ( mBArray ) ));
83+
assert_eq! (unsafe {
84+
& ( * ( 0 as * const C ) ) . mBConstArray as * const _ as
85+
usize } , 32usize , concat ! (
86+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
87+
! ( mBConstArray ) ));
7688
}
7789
impl Clone for C {
7890
fn clone(&self) -> Self { *self }
@@ -317,7 +329,7 @@ fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() {
317329
B<::std::os::raw::c_uint> ) ));
318330
}
319331
#[test]
320-
fn __bindgen_test_layout_B_open0__bindgen_ty_id_113_close0_instantiation() {
332+
fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() {
321333
assert_eq!(::std::mem::size_of::<B<*const ::std::os::raw::c_int>>() ,
322334
8usize , concat ! (
323335
"Size of template specialization: " , stringify ! (
@@ -368,6 +380,28 @@ fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() {
368380
) ));
369381
}
370382
#[test]
383+
fn __bindgen_test_layout_B_open0_array_int_1_close0_instantiation() {
384+
assert_eq!(::std::mem::size_of::<B<[::std::os::raw::c_int; 1usize]>>() ,
385+
4usize , concat ! (
386+
"Size of template specialization: " , stringify ! (
387+
B<[::std::os::raw::c_int; 1usize]> ) ));
388+
assert_eq!(::std::mem::align_of::<B<[::std::os::raw::c_int; 1usize]>>() ,
389+
4usize , concat ! (
390+
"Alignment of template specialization: " , stringify ! (
391+
B<[::std::os::raw::c_int; 1usize]> ) ));
392+
}
393+
#[test]
394+
fn __bindgen_test_layout_B_open0_array_const_int_1_close0_instantiation() {
395+
assert_eq!(::std::mem::size_of::<B<[::std::os::raw::c_int; 1usize]>>() ,
396+
4usize , concat ! (
397+
"Size of template specialization: " , stringify ! (
398+
B<[::std::os::raw::c_int; 1usize]> ) ));
399+
assert_eq!(::std::mem::align_of::<B<[::std::os::raw::c_int; 1usize]>>() ,
400+
4usize , concat ! (
401+
"Alignment of template specialization: " , stringify ! (
402+
B<[::std::os::raw::c_int; 1usize]> ) ));
403+
}
404+
#[test]
371405
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
372406
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
373407
concat ! (
@@ -379,7 +413,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
379413
Foo<::std::os::raw::c_int> ) ));
380414
}
381415
#[test]
382-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_144_close0_instantiation() {
416+
fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() {
383417
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
384418
24usize , concat ! (
385419
"Size of template specialization: " , stringify ! (
@@ -390,7 +424,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_144_close0_instantiation()
390424
Rooted<*mut ::std::os::raw::c_void> ) ));
391425
}
392426
#[test]
393-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_150_close0_instantiation() {
427+
fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() {
394428
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
395429
24usize , concat ! (
396430
"Size of template specialization: " , stringify ! (

tests/headers/template.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct C {
1919
B<volatile int> mBVolatile;
2020
B<const bool> mBConstBool;
2121
B<const char16_t> mBConstChar;
22+
B<int[1]> mBArray;
23+
B<const int[1]> mBConstArray;
2224
};
2325

2426
template<typename T>

0 commit comments

Comments
 (0)