Skip to content

Commit e0bd747

Browse files
committed
Never use spaces in generated name (fixes #844)
1 parent 3c98018 commit e0bd747

File tree

9 files changed

+97
-16
lines changed

9 files changed

+97
-16
lines changed

src/ir/ty.rs

+16
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ 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+
match ik {
91+
IntKind::Char { .. } => return Some("char"),
92+
IntKind::SChar => return Some("signed_char"),
93+
IntKind::UChar => return Some("unsigned_char"),
94+
IntKind::Short => return Some("short"),
95+
IntKind::UShort => return Some("unsigned_short"),
96+
IntKind::Int => return Some("int"),
97+
IntKind::UInt => return Some("unsigned_int"),
98+
IntKind::Long => return Some("long"),
99+
IntKind::ULong => return Some("unsigned_long"),
100+
IntKind::LongLong => return Some("longlong"),
101+
IntKind::ULongLong => return Some("unsigned_longlong"),
102+
_ => ()
103+
}
104+
}
89105
self.name.as_ref().map(|name| &**name)
90106
}
91107

tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod root {
1818
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
1919
}
2020
#[test]
21-
fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() {
21+
fn __bindgen_test_layout_Rooted_open0_c_int_close0_instantiation() {
2222
assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>()
2323
, 4usize , concat ! (
2424
"Size of template specialization: " , stringify ! (
@@ -29,7 +29,7 @@ pub mod root {
2929
root::Rooted<::std::os::raw::c_int> ) ));
3030
}
3131
#[test]
32-
fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation_1() {
32+
fn __bindgen_test_layout_Rooted_open0_c_int_close0_instantiation_1() {
3333
assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>()
3434
, 4usize , concat ! (
3535
"Size of template specialization: " , stringify ! (

tests/expectations/tests/non-type-params.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Default for UsesArray {
4242
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
4343
}
4444
#[test]
45-
fn __bindgen_test_layout_Array_open0_int_close0_instantiation() {
45+
fn __bindgen_test_layout_Array_open0_c_int_close0_instantiation() {
4646
assert_eq!(::std::mem::size_of::<[u32; 4usize]>() , 16usize , concat ! (
4747
"Size of template specialization: " , stringify ! (
4848
[u32; 4usize] ) ));
@@ -51,7 +51,7 @@ fn __bindgen_test_layout_Array_open0_int_close0_instantiation() {
5151
[u32; 4usize] ) ));
5252
}
5353
#[test]
54-
fn __bindgen_test_layout_Array_open0_char_close0_instantiation() {
54+
fn __bindgen_test_layout_Array_open0_c_char_close0_instantiation() {
5555
assert_eq!(::std::mem::size_of::<[u8; 16usize]>() , 16usize , concat ! (
5656
"Size of template specialization: " , stringify ! (
5757
[u8; 16usize] ) ));

tests/expectations/tests/opaque-template-instantiation.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ impl Default for ContainsInstantiation {
3939
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
4040
}
4141
#[repr(C)]
42-
#[derive(Debug, Default, Copy)]
42+
#[derive(Debug, Copy)]
4343
pub struct ContainsOpaqueInstantiation {
44-
pub opaque: u32,
44+
pub opaque: Template<::std::os::raw::c_int>,
4545
}
4646
#[test]
4747
fn bindgen_test_layout_ContainsOpaqueInstantiation() {
@@ -62,8 +62,11 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() {
6262
impl Clone for ContainsOpaqueInstantiation {
6363
fn clone(&self) -> Self { *self }
6464
}
65+
impl Default for ContainsOpaqueInstantiation {
66+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
67+
}
6568
#[test]
66-
fn __bindgen_test_layout_Template_open0_char_close0_instantiation() {
69+
fn __bindgen_test_layout_Template_open0_c_char_close0_instantiation() {
6770
assert_eq!(::std::mem::size_of::<Template<::std::os::raw::c_char>>() ,
6871
1usize , concat ! (
6972
"Size of template specialization: " , stringify ! (
@@ -73,3 +76,14 @@ fn __bindgen_test_layout_Template_open0_char_close0_instantiation() {
7376
"Alignment of template specialization: " , stringify ! (
7477
Template<::std::os::raw::c_char> ) ));
7578
}
79+
#[test]
80+
fn __bindgen_test_layout_Template_open0_c_int_close0_instantiation() {
81+
assert_eq!(::std::mem::size_of::<Template<::std::os::raw::c_int>>() ,
82+
4usize , concat ! (
83+
"Size of template specialization: " , stringify ! (
84+
Template<::std::os::raw::c_int> ) ));
85+
assert_eq!(::std::mem::align_of::<Template<::std::os::raw::c_int>>() ,
86+
4usize , concat ! (
87+
"Alignment of template specialization: " , stringify ! (
88+
Template<::std::os::raw::c_int> ) ));
89+
}

tests/expectations/tests/replace_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Default for Test {
3434
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3535
}
3636
#[test]
37-
fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() {
37+
fn __bindgen_test_layout_nsTArray_open0_c_long_close0_instantiation() {
3838
assert_eq!(::std::mem::size_of::<nsTArray>() , 4usize , concat ! (
3939
"Size of template specialization: " , stringify ! ( nsTArray )
4040
));

tests/expectations/tests/size_t_template.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Default for C {
2828
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
2929
}
3030
#[test]
31-
fn __bindgen_test_layout_Array_open0_int_close0_instantiation() {
31+
fn __bindgen_test_layout_Array_open0_c_int_close0_instantiation() {
3232
assert_eq!(::std::mem::size_of::<[u32; 3usize]>() , 12usize , concat ! (
3333
"Size of template specialization: " , stringify ! (
3434
[u32; 3usize] ) ));

tests/expectations/tests/template.rs

+49-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,43 @@ 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 mBBB: B<::std::os::raw::c_uint>,
35+
}
36+
#[test]
37+
fn bindgen_test_layout_C() {
38+
assert_eq!(::std::mem::size_of::<C>() , 4usize , concat ! (
39+
"Size of: " , stringify ! ( C ) ));
40+
assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
41+
"Alignment of " , stringify ! ( C ) ));
42+
assert_eq! (unsafe {
43+
& ( * ( 0 as * const C ) ) . mBBB as * const _ as usize } ,
44+
0usize , concat ! (
45+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
46+
! ( mBBB ) ));
47+
}
48+
impl Clone for C {
49+
fn clone(&self) -> Self { *self }
50+
}
51+
impl Default for C {
52+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
53+
}
54+
#[repr(C)]
2355
#[derive(Debug)]
2456
pub struct D {
2557
pub m_foo: D_MyFoo,
@@ -234,7 +266,7 @@ impl <T> Default for ReplacedWithoutDestructorFwd<T> {
234266
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
235267
}
236268
#[test]
237-
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() {
269+
fn __bindgen_test_layout_Foo_open0_c_int_c_int_close0_instantiation() {
238270
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
239271
concat ! (
240272
"Size of template specialization: " , stringify ! (
@@ -245,7 +277,18 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() {
245277
Foo<::std::os::raw::c_int> ) ));
246278
}
247279
#[test]
248-
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
280+
fn __bindgen_test_layout_B_open0_c_uint_close0_instantiation() {
281+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_uint>>() , 4usize ,
282+
concat ! (
283+
"Size of template specialization: " , stringify ! (
284+
B<::std::os::raw::c_uint> ) ));
285+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_uint>>() , 4usize ,
286+
concat ! (
287+
"Alignment of template specialization: " , stringify ! (
288+
B<::std::os::raw::c_uint> ) ));
289+
}
290+
#[test]
291+
fn __bindgen_test_layout_Foo_open0_c_int_c_int_close0_instantiation_1() {
249292
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
250293
concat ! (
251294
"Size of template specialization: " , stringify ! (
@@ -256,7 +299,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
256299
Foo<::std::os::raw::c_int> ) ));
257300
}
258301
#[test]
259-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() {
302+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_118_close0_instantiation() {
260303
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
261304
24usize , concat ! (
262305
"Size of template specialization: " , stringify ! (
@@ -267,7 +310,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation()
267310
Rooted<*mut ::std::os::raw::c_void> ) ));
268311
}
269312
#[test]
270-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation() {
313+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_124_close0_instantiation() {
271314
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
272315
24usize , concat ! (
273316
"Size of template specialization: " , stringify ! (
@@ -278,7 +321,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation()
278321
Rooted<*mut ::std::os::raw::c_void> ) ));
279322
}
280323
#[test]
281-
fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() {
324+
fn __bindgen_test_layout_WithDtor_open0_c_int_close0_instantiation() {
282325
assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
283326
4usize , concat ! (
284327
"Size of template specialization: " , stringify ! (
@@ -289,7 +332,7 @@ fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() {
289332
WithDtor<::std::os::raw::c_int> ) ));
290333
}
291334
#[test]
292-
fn __bindgen_test_layout_Opaque_open0_int_close0_instantiation() {
335+
fn __bindgen_test_layout_Opaque_open0_c_int_close0_instantiation() {
293336
assert_eq!(::std::mem::size_of::<u32>() , 4usize , concat ! (
294337
"Size of template specialization: " , stringify ! ( u32 ) ));
295338
assert_eq!(::std::mem::align_of::<u32>() , 4usize , concat ! (

tests/expectations/tests/typeref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl Default for Bar {
124124
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
125125
}
126126
#[test]
127-
fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() {
127+
fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_c_int_close0_instantiation() {
128128
assert_eq!(::std::mem::size_of::<mozilla_StyleShapeSource>() , 8usize ,
129129
concat ! (
130130
"Size of template specialization: " , stringify ! (

tests/headers/template.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ 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+
};
16+
917
template<typename T>
1018
class D {
1119
typedef Foo<int, int> MyFoo;

0 commit comments

Comments
 (0)