Skip to content

Commit c681687

Browse files
committed
ir: Don't assume that base classes are already resolved.
Fixes #359
1 parent 2766951 commit c681687

8 files changed

+75
-41
lines changed

libbindgen/src/ir/comp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,7 @@ impl CompInfo {
654654
ci.has_vtable = cur.is_virtual_base();
655655
}
656656
let type_id =
657-
Item::from_ty(&cur.cur_type(), Some(cur), None, ctx)
658-
.expect("BaseSpecifier");
657+
Item::from_ty_or_ref(cur.cur_type(), Some(cur), None, ctx);
659658
ci.base_members.push(type_id);
660659
}
661660
CXCursor_Constructor |

libbindgen/tests/expectations/tests/anon_union.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ pub struct TErrorResult__bindgen_ty_1<T> {
6262
pub bindgen_union_field: u64,
6363
pub _phantom_0: ::std::marker::PhantomData<T>,
6464
}
65-
#[test]
66-
fn __bindgen_test_layout_template_1() {
67-
assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() ,
68-
24usize);
69-
assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() ,
70-
8usize);
71-
}
7265
#[repr(C)]
7366
#[derive(Debug, Copy)]
7467
pub struct ErrorResult {
@@ -82,3 +75,10 @@ fn bindgen_test_layout_ErrorResult() {
8275
impl Clone for ErrorResult {
8376
fn clone(&self) -> Self { *self }
8477
}
78+
#[test]
79+
fn __bindgen_test_layout_template_1() {
80+
assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() ,
81+
24usize);
82+
assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() ,
83+
8usize);
84+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct std_char_traits<_CharT> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
12+
}
13+
#[repr(C)]
14+
#[derive(Debug, Copy)]
15+
pub struct __gnu_cxx_char_traits {
16+
pub _address: u8,
17+
}
18+
impl Clone for __gnu_cxx_char_traits {
19+
fn clone(&self) -> Self { *self }
20+
}

libbindgen/tests/expectations/tests/crtp.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ pub struct Base<T> {
1010
pub _address: u8,
1111
pub _phantom_0: ::std::marker::PhantomData<T>,
1212
}
13-
#[test]
14-
fn __bindgen_test_layout_template_1() {
15-
assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize);
16-
assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize);
17-
}
1813
#[repr(C)]
1914
#[derive(Debug, Copy)]
2015
pub struct Derived {
@@ -34,13 +29,6 @@ pub struct BaseWithDestructor<T> {
3429
pub _address: u8,
3530
pub _phantom_0: ::std::marker::PhantomData<T>,
3631
}
37-
#[test]
38-
fn __bindgen_test_layout_template_2() {
39-
assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
40-
, 1usize);
41-
assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
42-
, 1usize);
43-
}
4432
#[repr(C)]
4533
#[derive(Debug)]
4634
pub struct DerivedFromBaseWithDestructor {
@@ -53,3 +41,15 @@ fn bindgen_test_layout_DerivedFromBaseWithDestructor() {
5341
assert_eq!(::std::mem::align_of::<DerivedFromBaseWithDestructor>() ,
5442
1usize);
5543
}
44+
#[test]
45+
fn __bindgen_test_layout_template_1() {
46+
assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize);
47+
assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize);
48+
}
49+
#[test]
50+
fn __bindgen_test_layout_template_2() {
51+
assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
52+
, 1usize);
53+
assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
54+
, 1usize);
55+
}

libbindgen/tests/expectations/tests/forward-inherit-struct-with-fields.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
#[repr(C)]
88
#[derive(Debug, Copy, Clone)]
9-
pub struct RootedBase<T> {
10-
pub foo: *mut T,
11-
pub next: *mut Rooted<T>,
9+
pub struct Rooted<T> {
10+
pub _base: js_RootedBase<T>,
1211
}
1312
#[repr(C)]
1413
#[derive(Debug, Copy, Clone)]
15-
pub struct Rooted<T> {
16-
pub _base: RootedBase<T>,
14+
pub struct js_RootedBase<T> {
15+
pub foo: *mut T,
16+
pub next: *mut Rooted<T>,
1717
}

libbindgen/tests/expectations/tests/forward-inherit-struct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
#[repr(C)]
88
#[derive(Debug, Copy, Clone)]
9-
pub struct RootedBase<T> {
9+
pub struct Rooted<T> {
1010
pub _address: u8,
1111
pub _phantom_0: ::std::marker::PhantomData<T>,
1212
}
1313
#[repr(C)]
1414
#[derive(Debug, Copy, Clone)]
15-
pub struct Rooted<T> {
15+
pub struct js_RootedBase<T> {
1616
pub _address: u8,
1717
pub _phantom_0: ::std::marker::PhantomData<T>,
1818
}

libbindgen/tests/expectations/tests/vtable_recursive_sig.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
#![allow(non_snake_case)]
55

66

7+
#[repr(C)]
8+
#[derive(Debug, Copy)]
9+
pub struct Derived {
10+
pub _base: Base,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Derived() {
14+
assert_eq!(::std::mem::size_of::<Derived>() , 8usize);
15+
assert_eq!(::std::mem::align_of::<Derived>() , 8usize);
16+
}
17+
impl Clone for Derived {
18+
fn clone(&self) -> Self { *self }
19+
}
720
#[repr(C)]
821
pub struct Base__bindgen_vtable {
922
}
@@ -20,16 +33,3 @@ fn bindgen_test_layout_Base() {
2033
impl Clone for Base {
2134
fn clone(&self) -> Self { *self }
2235
}
23-
#[repr(C)]
24-
#[derive(Debug, Copy)]
25-
pub struct Derived {
26-
pub _base: Base,
27-
}
28-
#[test]
29-
fn bindgen_test_layout_Derived() {
30-
assert_eq!(::std::mem::size_of::<Derived>() , 8usize);
31-
assert_eq!(::std::mem::align_of::<Derived>() , 8usize);
32-
}
33-
impl Clone for Derived {
34-
fn clone(&self) -> Self { *self }
35-
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace std
2+
{
3+
template < typename > struct char_traits;
4+
}
5+
namespace __gnu_cxx
6+
{
7+
template < typename > struct char_traits;
8+
}
9+
namespace std
10+
{
11+
template < class _CharT > struct char_traits:__gnu_cxx::char_traits <
12+
_CharT >
13+
{
14+
};
15+
}

0 commit comments

Comments
 (0)