Skip to content

Commit 156ae53

Browse files
author
bors-servo
authored
Auto merge of #845 - servo:fix-spaces, r=fitzgen
Never use spaces in generated name (fixes #844) None
2 parents 3c98018 + 333f21a commit 156ae53

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

src/ir/ty.rs

+18
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ impl Type {
8686

8787
/// Get this type's name.
8888
pub fn name(&self) -> Option<&str> {
89+
if let TypeKind::Int(ik) = *self.kind() {
90+
// these types will return spaces in their names
91+
// unless we manually change it
92+
match ik {
93+
IntKind::Char { .. } => return Some("char"),
94+
IntKind::SChar => return Some("signed_char"),
95+
IntKind::UChar => return Some("unsigned_char"),
96+
IntKind::Short => return Some("short"),
97+
IntKind::UShort => return Some("unsigned_short"),
98+
IntKind::Int => return Some("int"),
99+
IntKind::UInt => return Some("unsigned_int"),
100+
IntKind::Long => return Some("long"),
101+
IntKind::ULong => return Some("unsigned_long"),
102+
IntKind::LongLong => return Some("longlong"),
103+
IntKind::ULongLong => return Some("unsigned_longlong"),
104+
_ => ()
105+
}
106+
}
89107
self.name.as_ref().map(|name| &**name)
90108
}
91109

tests/expectations/tests/template.rs

+95-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,60 @@ pub struct Foo<T> {
1515
impl <T> Default for Foo<T> {
1616
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
1717
}
18+
#[repr(C)]
19+
#[derive(Debug, Copy, Clone)]
20+
pub struct B<T> {
21+
pub m_member: T,
22+
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
23+
}
24+
impl <T> Default for B<T> {
25+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
26+
}
1827
extern "C" {
1928
#[link_name = "_Z3bar3FooIiiE"]
2029
pub fn bar(foo: Foo<::std::os::raw::c_int>);
2130
}
2231
#[repr(C)]
32+
#[derive(Debug, Copy)]
33+
pub struct C {
34+
pub mB: B<::std::os::raw::c_uint>,
35+
pub mBConstPtr: B<*const ::std::os::raw::c_int>,
36+
pub mBConst: B<::std::os::raw::c_int>,
37+
pub mBVolatile: B<::std::os::raw::c_int>,
38+
}
39+
#[test]
40+
fn bindgen_test_layout_C() {
41+
assert_eq!(::std::mem::size_of::<C>() , 24usize , concat ! (
42+
"Size of: " , stringify ! ( C ) ));
43+
assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
44+
"Alignment of " , stringify ! ( C ) ));
45+
assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . mB as * const _ as usize
46+
} , 0usize , concat ! (
47+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
48+
! ( mB ) ));
49+
assert_eq! (unsafe {
50+
& ( * ( 0 as * const C ) ) . mBConstPtr as * const _ as usize
51+
} , 8usize , concat ! (
52+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
53+
! ( mBConstPtr ) ));
54+
assert_eq! (unsafe {
55+
& ( * ( 0 as * const C ) ) . mBConst as * const _ as usize } ,
56+
16usize , concat ! (
57+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
58+
! ( mBConst ) ));
59+
assert_eq! (unsafe {
60+
& ( * ( 0 as * const C ) ) . mBVolatile as * const _ as usize
61+
} , 20usize , concat ! (
62+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
63+
! ( mBVolatile ) ));
64+
}
65+
impl Clone for C {
66+
fn clone(&self) -> Self { *self }
67+
}
68+
impl Default for C {
69+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
70+
}
71+
#[repr(C)]
2372
#[derive(Debug)]
2473
pub struct D {
2574
pub m_foo: D_MyFoo,
@@ -245,6 +294,50 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() {
245294
Foo<::std::os::raw::c_int> ) ));
246295
}
247296
#[test]
297+
fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() {
298+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_uint>>() , 4usize ,
299+
concat ! (
300+
"Size of template specialization: " , stringify ! (
301+
B<::std::os::raw::c_uint> ) ));
302+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_uint>>() , 4usize ,
303+
concat ! (
304+
"Alignment of template specialization: " , stringify ! (
305+
B<::std::os::raw::c_uint> ) ));
306+
}
307+
#[test]
308+
fn __bindgen_test_layout_B_open0__bindgen_ty_id_111_close0_instantiation() {
309+
assert_eq!(::std::mem::size_of::<B<*const ::std::os::raw::c_int>>() ,
310+
8usize , concat ! (
311+
"Size of template specialization: " , stringify ! (
312+
B<*const ::std::os::raw::c_int> ) ));
313+
assert_eq!(::std::mem::align_of::<B<*const ::std::os::raw::c_int>>() ,
314+
8usize , concat ! (
315+
"Alignment of template specialization: " , stringify ! (
316+
B<*const ::std::os::raw::c_int> ) ));
317+
}
318+
#[test]
319+
fn __bindgen_test_layout_B_open0_int_close0_instantiation() {
320+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_int>>() , 4usize ,
321+
concat ! (
322+
"Size of template specialization: " , stringify ! (
323+
B<::std::os::raw::c_int> ) ));
324+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_int>>() , 4usize ,
325+
concat ! (
326+
"Alignment of template specialization: " , stringify ! (
327+
B<::std::os::raw::c_int> ) ));
328+
}
329+
#[test]
330+
fn __bindgen_test_layout_B_open0_int_close0_instantiation_1() {
331+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_int>>() , 4usize ,
332+
concat ! (
333+
"Size of template specialization: " , stringify ! (
334+
B<::std::os::raw::c_int> ) ));
335+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_int>>() , 4usize ,
336+
concat ! (
337+
"Alignment of template specialization: " , stringify ! (
338+
B<::std::os::raw::c_int> ) ));
339+
}
340+
#[test]
248341
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
249342
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
250343
concat ! (
@@ -256,7 +349,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
256349
Foo<::std::os::raw::c_int> ) ));
257350
}
258351
#[test]
259-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() {
352+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_134_close0_instantiation() {
260353
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
261354
24usize , concat ! (
262355
"Size of template specialization: " , stringify ! (
@@ -267,7 +360,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation()
267360
Rooted<*mut ::std::os::raw::c_void> ) ));
268361
}
269362
#[test]
270-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation() {
363+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_140_close0_instantiation() {
271364
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
272365
24usize , concat ! (
273366
"Size of template specialization: " , stringify ! (

tests/headers/template.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ template<typename T, typename U> class Foo {
44
T m_member_arr[1];
55
};
66

7+
template<typename T> class B {
8+
T m_member;
9+
};
10+
711
void bar(Foo<int, int> foo);
812

13+
struct C {
14+
B<unsigned int> mB;
15+
B<const int*> mBConstPtr;
16+
B<const int> mBConst;
17+
B<volatile int> mBVolatile;
18+
};
19+
920
template<typename T>
1021
class D {
1122
typedef Foo<int, int> MyFoo;

0 commit comments

Comments
 (0)