Skip to content

Commit a6956dd

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 + 5d409fe commit a6956dd

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
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/template.rs

+44-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,42 @@ 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+
}
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 { & ( * ( 0 as * const C ) ) . mB as * const _ as usize
43+
} , 0usize , concat ! (
44+
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
45+
! ( mB ) ));
46+
}
47+
impl Clone for C {
48+
fn clone(&self) -> Self { *self }
49+
}
50+
impl Default for C {
51+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
52+
}
53+
#[repr(C)]
2354
#[derive(Debug)]
2455
pub struct D {
2556
pub m_foo: D_MyFoo,
@@ -245,6 +276,17 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() {
245276
Foo<::std::os::raw::c_int> ) ));
246277
}
247278
#[test]
279+
fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() {
280+
assert_eq!(::std::mem::size_of::<B<::std::os::raw::c_uint>>() , 4usize ,
281+
concat ! (
282+
"Size of template specialization: " , stringify ! (
283+
B<::std::os::raw::c_uint> ) ));
284+
assert_eq!(::std::mem::align_of::<B<::std::os::raw::c_uint>>() , 4usize ,
285+
concat ! (
286+
"Alignment of template specialization: " , stringify ! (
287+
B<::std::os::raw::c_uint> ) ));
288+
}
289+
#[test]
248290
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
249291
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
250292
concat ! (
@@ -256,7 +298,7 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
256298
Foo<::std::os::raw::c_int> ) ));
257299
}
258300
#[test]
259-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() {
301+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_118_close0_instantiation() {
260302
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
261303
24usize , concat ! (
262304
"Size of template specialization: " , stringify ! (
@@ -267,7 +309,7 @@ fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation()
267309
Rooted<*mut ::std::os::raw::c_void> ) ));
268310
}
269311
#[test]
270-
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation() {
312+
fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_124_close0_instantiation() {
271313
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
272314
24usize , concat ! (
273315
"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)