Skip to content

Commit 877b65c

Browse files
author
bors-servo
authored
Auto merge of rust-lang#845 - servo:fix-spaces, r=emilio
Never use spaces in generated name (fixes rust-lang#844) None
2 parents 3c98018 + 2d949e2 commit 877b65c

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-3
lines changed

src/ir/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,13 @@ impl<'ctx> BindgenContext<'ctx> {
13911391
_ => return None,
13921392
};
13931393

1394-
let spelling = ty.spelling();
1394+
let mut spelling = ty.spelling();
1395+
// avoid the allocation if possible
1396+
if spelling.contains(' ') {
1397+
// These names are used in generated test names,
1398+
// they should be valid identifiers
1399+
spelling = spelling.replace(' ', "_");
1400+
}
13951401
let is_const = ty.is_const();
13961402
let layout = ty.fallible_layout().ok();
13971403
let ty = Type::new(Some(spelling), layout, type_kind, is_const);

tests/expectations/tests/template.rs

+125-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,72 @@ 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+
pub mBConstBool: B<bool>,
39+
pub mBConstChar: B<u16>,
40+
}
41+
#[test]
42+
fn bindgen_test_layout_C() {
43+
assert_eq!(::std::mem::size_of::<C>() , 32usize , concat ! (
44+
"Size of: " , stringify ! ( C ) ));
45+
assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
46+
"Alignment of " , stringify ! ( C ) ));
47+
assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . mB as * const _ as usize
48+
} , 0usize , concat ! (
49+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
50+
! ( mB ) ));
51+
assert_eq! (unsafe {
52+
& ( * ( 0 as * const C ) ) . mBConstPtr as * const _ as usize
53+
} , 8usize , concat ! (
54+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
55+
! ( mBConstPtr ) ));
56+
assert_eq! (unsafe {
57+
& ( * ( 0 as * const C ) ) . mBConst as * const _ as usize } ,
58+
16usize , concat ! (
59+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
60+
! ( mBConst ) ));
61+
assert_eq! (unsafe {
62+
& ( * ( 0 as * const C ) ) . mBVolatile as * const _ as usize
63+
} , 20usize , concat ! (
64+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
65+
! ( mBVolatile ) ));
66+
assert_eq! (unsafe {
67+
& ( * ( 0 as * const C ) ) . mBConstBool as * const _ as usize
68+
} , 24usize , concat ! (
69+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
70+
! ( mBConstBool ) ));
71+
assert_eq! (unsafe {
72+
& ( * ( 0 as * const C ) ) . mBConstChar as * const _ as usize
73+
} , 26usize , concat ! (
74+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
75+
! ( mBConstChar ) ));
76+
}
77+
impl Clone for C {
78+
fn clone(&self) -> Self { *self }
79+
}
80+
impl Default for C {
81+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
82+
}
83+
#[repr(C)]
2384
#[derive(Debug)]
2485
pub struct D {
2586
pub m_foo: D_MyFoo,
@@ -245,6 +306,68 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() {
245306
Foo<::std::os::raw::c_int> ) ));
246307
}
247308
#[test]
309+
fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() {
310+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_uint>>() , 4usize ,
311+
concat ! (
312+
"Size of template specialization: " , stringify ! (
313+
B<::std::os::raw::c_uint> ) ));
314+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_uint>>() , 4usize ,
315+
concat ! (
316+
"Alignment of template specialization: " , stringify ! (
317+
B<::std::os::raw::c_uint> ) ));
318+
}
319+
#[test]
320+
fn __bindgen_test_layout_B_open0__bindgen_ty_id_113_close0_instantiation() {
321+
assert_eq!(::std::mem::size_of::<B<*const ::std::os::raw::c_int>>() ,
322+
8usize , concat ! (
323+
"Size of template specialization: " , stringify ! (
324+
B<*const ::std::os::raw::c_int> ) ));
325+
assert_eq!(::std::mem::align_of::<B<*const ::std::os::raw::c_int>>() ,
326+
8usize , concat ! (
327+
"Alignment of template specialization: " , stringify ! (
328+
B<*const ::std::os::raw::c_int> ) ));
329+
}
330+
#[test]
331+
fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() {
332+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_int>>() , 4usize ,
333+
concat ! (
334+
"Size of template specialization: " , stringify ! (
335+
B<::std::os::raw::c_int> ) ));
336+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_int>>() , 4usize ,
337+
concat ! (
338+
"Alignment of template specialization: " , stringify ! (
339+
B<::std::os::raw::c_int> ) ));
340+
}
341+
#[test]
342+
fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() {
343+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_int>>() , 4usize ,
344+
concat ! (
345+
"Size of template specialization: " , stringify ! (
346+
B<::std::os::raw::c_int> ) ));
347+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_int>>() , 4usize ,
348+
concat ! (
349+
"Alignment of template specialization: " , stringify ! (
350+
B<::std::os::raw::c_int> ) ));
351+
}
352+
#[test]
353+
fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() {
354+
assert_eq!(::std::mem::size_of::<B<bool>>() , 1usize , concat ! (
355+
"Size of template specialization: " , stringify ! ( B<bool> )
356+
));
357+
assert_eq!(::std::mem::align_of::<B<bool>>() , 1usize , concat ! (
358+
"Alignment of template specialization: " , stringify ! (
359+
B<bool> ) ));
360+
}
361+
#[test]
362+
fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() {
363+
assert_eq!(::std::mem::size_of::<B<u16>>() , 2usize , concat ! (
364+
"Size of template specialization: " , stringify ! ( B<u16> )
365+
));
366+
assert_eq!(::std::mem::align_of::<B<u16>>() , 2usize , concat ! (
367+
"Alignment of template specialization: " , stringify ! ( B<u16>
368+
) ));
369+
}
370+
#[test]
248371
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
249372
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
250373
concat ! (
@@ -256,7 +379,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
256379
Foo<::std::os::raw::c_int> ) ));
257380
}
258381
#[test]
259-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() {
382+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_144_close0_instantiation() {
260383
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
261384
24usize , concat ! (
262385
"Size of template specialization: " , stringify ! (
@@ -267,7 +390,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation()
267390
Rooted<*mut ::std::os::raw::c_void> ) ));
268391
}
269392
#[test]
270-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation() {
393+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_150_close0_instantiation() {
271394
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
272395
24usize , concat ! (
273396
"Size of template specialization: " , stringify ! (

tests/headers/template.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
// bindgen-flags: -- -std=c++11
2+
//
13
template<typename T, typename U> class Foo {
24
T m_member;
35
T* m_member_ptr;
46
T m_member_arr[1];
57
};
68

9+
template<typename T> class B {
10+
T m_member;
11+
};
12+
713
void bar(Foo<int, int> foo);
814

15+
struct C {
16+
B<unsigned int> mB;
17+
B<const int*> mBConstPtr;
18+
B<const int> mBConst;
19+
B<volatile int> mBVolatile;
20+
B<const bool> mBConstBool;
21+
B<const char16_t> mBConstChar;
22+
};
23+
924
template<typename T>
1025
class D {
1126
typedef Foo<int, int> MyFoo;

0 commit comments

Comments
 (0)