Skip to content

Commit 3ba3a76

Browse files
author
bors-servo
authored
Auto merge of #360 - emilio:base, r=fitzgen
Don't assume that base classes are already resolved. Since it may not be the case. Fixes #359 Also fixes a few other test cases in the codebase that had the wrong namespace relationship. r? @fitzgen
2 parents cbc0304 + b93faf9 commit 3ba3a76

15 files changed

+117
-74
lines changed

libbindgen/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license = "BSD-3-Clause"
1212
name = "libbindgen"
1313
readme = "README.md"
1414
repository = "https://github.com/servo/rust-bindgen"
15-
version = "0.1.3"
15+
version = "0.1.4"
1616
workspace = ".."
1717

1818
[dev-dependencies]
@@ -28,7 +28,6 @@ cexpr = "0.2"
2828
cfg-if = "0.1.0"
2929
clang-sys = { version = "0.12", features = ["runtime", "clang_3_9"] }
3030
lazy_static = "0.2.1"
31-
libc = "0.2"
3231
rustc-serialize = "0.3.19"
3332
syntex_syntax = "0.50"
3433
regex = "0.1"

libbindgen/src/ir/comp.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,7 @@ impl CompInfo {
644644
return CXChildVisit_Continue;
645645
}
646646

647-
let default_type = Item::from_ty(&cur.cur_type(),
648-
Some(cur),
649-
Some(potential_id),
650-
ctx)
651-
.ok();
652647
let param = Item::named_type(cur.spelling(),
653-
default_type,
654648
potential_id,
655649
ctx);
656650
ci.template_args.push(param);
@@ -660,8 +654,7 @@ impl CompInfo {
660654
ci.has_vtable = cur.is_virtual_base();
661655
}
662656
let type_id =
663-
Item::from_ty(&cur.cur_type(), Some(cur), None, ctx)
664-
.expect("BaseSpecifier");
657+
Item::from_ty_or_ref(cur.cur_type(), Some(cur), None, ctx);
665658
ci.base_members.push(type_id);
666659
}
667660
CXCursor_Constructor |

libbindgen/src/ir/item.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ impl Item {
499499
parent_template_args.iter().any(|parent_item| {
500500
let parent_ty = ctx.resolve_type(*parent_item);
501501
match (parent_ty.kind(), item_ty.kind()) {
502-
(&TypeKind::Named(ref n, _),
503-
&TypeKind::Named(ref i, _)) => n == i,
502+
(&TypeKind::Named(ref n),
503+
&TypeKind::Named(ref i)) => n == i,
504504
_ => false,
505505
}
506506
})
@@ -1163,7 +1163,6 @@ impl ClangItemParser for Item {
11631163
ty.spelling());
11641164
Ok(Self::named_type_with_id(id,
11651165
ty.spelling(),
1166-
None,
11671166
relevant_parent_id,
11681167
ctx))
11691168
} else {
@@ -1189,7 +1188,6 @@ impl ClangItemParser for Item {
11891188
/// available yet.
11901189
fn named_type_with_id<S>(id: ItemId,
11911190
name: S,
1192-
default: Option<ItemId>,
11931191
parent_id: ItemId,
11941192
ctx: &mut BindgenContext)
11951193
-> ItemId
@@ -1203,22 +1201,21 @@ impl ClangItemParser for Item {
12031201
None,
12041202
None,
12051203
parent_id,
1206-
ItemKind::Type(Type::named(name, default))),
1204+
ItemKind::Type(Type::named(name))),
12071205
None,
12081206
None);
12091207

12101208
id
12111209
}
12121210

12131211
fn named_type<S>(name: S,
1214-
default: Option<ItemId>,
12151212
parent_id: ItemId,
12161213
ctx: &mut BindgenContext)
12171214
-> ItemId
12181215
where S: Into<String>,
12191216
{
12201217
let id = ctx.next_item_id();
1221-
Self::named_type_with_id(id, name, default, parent_id, ctx)
1218+
Self::named_type_with_id(id, name, parent_id, ctx)
12221219
}
12231220
}
12241221

libbindgen/src/ir/ty.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ impl Type {
140140
}
141141

142142
/// Creates a new named type, with name `name`.
143-
pub fn named(name: String, default: Option<ItemId>) -> Self {
143+
pub fn named(name: String) -> Self {
144144
assert!(!name.is_empty());
145145
// TODO: stop duplicating the name, it's stupid.
146-
let kind = TypeKind::Named(name.clone(), default);
146+
let kind = TypeKind::Named(name.clone());
147147
Self::new(Some(name), None, kind, false)
148148
}
149149

@@ -318,12 +318,12 @@ impl Type {
318318
ty: &Type)
319319
-> bool {
320320
let name = match *ty.kind() {
321-
TypeKind::Named(ref name, _) => name,
321+
TypeKind::Named(ref name) => name,
322322
ref other @ _ => unreachable!("Not a named type: {:?}", other),
323323
};
324324

325325
match self.kind {
326-
TypeKind::Named(ref this_name, _) => this_name == name,
326+
TypeKind::Named(ref this_name) => this_name == name,
327327
TypeKind::ResolvedTypeRef(t) |
328328
TypeKind::Array(t, _) |
329329
TypeKind::Pointer(t) |
@@ -478,9 +478,8 @@ pub enum TypeKind {
478478
/// replace one type with another.
479479
ResolvedTypeRef(ItemId),
480480

481-
/// A named type, that is, a template parameter, with an optional default
482-
/// type.
483-
Named(String, Option<ItemId>),
481+
/// A named type, that is, a template parameter.
482+
Named(String),
484483
}
485484

486485
impl Type {
@@ -675,15 +674,8 @@ impl Type {
675674
return CXChildVisit_Continue;
676675
}
677676

678-
let default_type =
679-
Item::from_ty(&cur.cur_type(),
680-
Some(cur),
681-
Some(potential_id),
682-
ctx)
683-
.ok();
684677
let param =
685678
Item::named_type(cur.spelling(),
686-
default_type,
687679
potential_id,
688680
ctx);
689681
args.push(param);
@@ -903,7 +895,6 @@ impl TypeCollector for Type {
903895
TypeKind::Reference(inner) |
904896
TypeKind::Array(inner, _) |
905897
TypeKind::Alias(_, inner) |
906-
TypeKind::Named(_, Some(inner)) |
907898
TypeKind::ResolvedTypeRef(inner) => {
908899
types.insert(inner);
909900
}
@@ -919,6 +910,7 @@ impl TypeCollector for Type {
919910
TypeKind::Function(ref sig) => {
920911
sig.collect_types(context, types, item)
921912
}
913+
TypeKind::Named(_) => {},
922914
// FIXME: Pending types!
923915
ref other @ _ => {
924916
debug!("<Type as TypeCollector>::collect_types: Ignoring: \

libbindgen/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
#![deny(missing_docs)]
99
#![deny(warnings)]
10+
#![deny(unused_extern_crates)]
1011

1112
// We internally use the deprecated BindgenOptions all over the place. Once we
1213
// remove its `pub` declaration, we can un-deprecate it and remove this pragma.
@@ -17,13 +18,13 @@
1718
#![allow(non_upper_case_globals)]
1819

1920
#[macro_use]
21+
#[allow(unused_extern_crates)]
2022
extern crate cfg_if;
2123
extern crate cexpr;
2224
extern crate syntex_syntax as syntax;
2325
extern crate aster;
2426
extern crate quasi;
2527
extern crate clang_sys;
26-
extern crate libc;
2728
extern crate regex;
2829
#[macro_use]
2930
extern crate lazy_static;

libbindgen/src/parse.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub trait ClangItemParser: Sized {
8282

8383
/// Create a named template type.
8484
fn named_type<S>(name: S,
85-
default: Option<ItemId>,
8685
parent: ItemId,
8786
context: &mut BindgenContext)
8887
-> ItemId
@@ -92,7 +91,6 @@ pub trait ClangItemParser: Sized {
9291
/// `ItemId`.
9392
fn named_type_with_id<S>(id: ItemId,
9493
name: S,
95-
default: Option<ItemId>,
9694
parent: ItemId,
9795
context: &mut BindgenContext)
9896
-> ItemId

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
}
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 JS_PersistentRooted<c> {
10+
pub _base: a,
11+
pub _phantom_0: ::std::marker::PhantomData<c>,
12+
}
13+
#[repr(C)]
14+
#[derive(Debug, Copy)]
15+
pub struct a {
16+
pub b: *mut a,
17+
}
18+
impl Clone for a {
19+
fn clone(&self) -> Self { *self }
20+
}

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)