Skip to content

Commit 5e99041

Browse files
committed
Pass the potential id to be used as the type wrapper id.
This should fix the MSVC problems. Signed-off-by: Emilio Cobos Álvarez <[email protected]>
1 parent 82a74d0 commit 5e99041

File tree

6 files changed

+65
-58
lines changed

6 files changed

+65
-58
lines changed

src/ir/context.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,22 +433,22 @@ impl<'ctx> BindgenContext<'ctx> {
433433
/// };
434434
/// ```
435435
fn build_template_wrapper(&mut self,
436+
with_id: ItemId,
436437
wrapping: ItemId,
437438
parent_id: ItemId,
438439
ty: &clang::Type,
439440
location: clang::Cursor) -> ItemId {
440441
use clangll::*;
441442
let mut args = vec![];
442443
let mut found_invalid_template_ref = false;
443-
let self_id = ItemId::next();
444444
location.visit(|c, _| {
445445
if c.kind() == CXCursor_TemplateRef &&
446446
c.cur_type().kind() == CXType_Invalid {
447447
found_invalid_template_ref = true;
448448
}
449449
if c.kind() == CXCursor_TypeRef {
450450
let new_ty =
451-
Item::from_ty_or_ref(c.cur_type(), Some(*c), Some(self_id), self);
451+
Item::from_ty_or_ref(c.cur_type(), Some(*c), Some(with_id), self);
452452
args.push(new_ty);
453453
}
454454
CXChildVisit_Continue
@@ -494,17 +494,18 @@ impl<'ctx> BindgenContext<'ctx> {
494494
let name = ty.spelling();
495495
let name = if name.is_empty() { None } else { Some(name) };
496496
let ty = Type::new(name, ty.fallible_layout().ok(), type_kind, ty.is_const());
497-
Item::new(self_id, None, None, parent_id, ItemKind::Type(ty))
497+
Item::new(with_id, None, None, parent_id, ItemKind::Type(ty))
498498
};
499499

500500
// Bypass all the validations in add_item explicitly.
501-
self.items.insert(self_id, item);
502-
self_id
501+
self.items.insert(with_id, item);
502+
with_id
503503
}
504504

505505
/// Looks up for an already resolved type, either because it's builtin, or
506506
/// because we already have it in the map.
507507
pub fn builtin_or_resolved_ty(&mut self,
508+
with_id: ItemId,
508509
parent_id: Option<ItemId>,
509510
ty: &clang::Type,
510511
location: Option<clang::Cursor>) -> Option<ItemId> {
@@ -533,6 +534,7 @@ impl<'ctx> BindgenContext<'ctx> {
533534
if let Some(id) = id {
534535
debug!("Already resolved ty {:?}, {:?}, {:?} {:?}",
535536
id, declaration, ty, location);
537+
536538
// If the declaration existed, we *might* be done, but it's not
537539
// the case for class templates, where the template arguments
538540
// may vary.
@@ -548,11 +550,12 @@ impl<'ctx> BindgenContext<'ctx> {
548550
*ty != canonical_declaration.cur_type() &&
549551
location.is_some() && parent_id.is_some() {
550552
return Some(
551-
self.build_template_wrapper(id, parent_id.unwrap(), ty,
553+
self.build_template_wrapper(with_id, id,
554+
parent_id.unwrap(), ty,
552555
location.unwrap()));
553556
}
554557

555-
return Some(self.build_ty_wrapper(id, parent_id, ty));
558+
return Some(self.build_ty_wrapper(with_id, id, parent_id, ty));
556559
}
557560
}
558561

@@ -568,19 +571,19 @@ impl<'ctx> BindgenContext<'ctx> {
568571
// We should probably make the constness tracking separate, so it doesn't
569572
// bloat that much, but hey, we already bloat the heck out of builtin types.
570573
fn build_ty_wrapper(&mut self,
574+
with_id: ItemId,
571575
wrapped_id: ItemId,
572576
parent_id: Option<ItemId>,
573577
ty: &clang::Type) -> ItemId {
574-
let id = ItemId::next();
575578
let spelling = ty.spelling();
576579
let is_const = ty.is_const();
577580
let layout = ty.fallible_layout().ok();
578581
let type_kind = TypeKind::ResolvedTypeRef(wrapped_id);
579582
let ty = Type::new(Some(spelling), layout, type_kind, is_const);
580-
let item = Item::new(id, None, None,
583+
let item = Item::new(with_id, None, None,
581584
parent_id.unwrap_or(self.current_module), ItemKind::Type(ty));
582585
self.add_builtin_item(item);
583-
id
586+
with_id
584587
}
585588

586589
fn build_builtin_ty(&mut self,

src/ir/item.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,9 @@ impl ClangItemParser for Item {
633633
.expect("Unable to resolve type");
634634
}
635635

636-
if let Some(ty) = context.builtin_or_resolved_ty(parent_id, &ty, location) {
636+
if let Some(ty) = context.builtin_or_resolved_ty(potential_id,
637+
parent_id, &ty,
638+
location) {
637639
debug!("{:?} already resolved: {:?}", ty, location);
638640
return ty;
639641
}
@@ -695,7 +697,8 @@ impl ClangItemParser for Item {
695697
context.replace(replaced, id);
696698
}
697699

698-
if let Some(ty) = context.builtin_or_resolved_ty(parent_id, ty, location) {
700+
if let Some(ty) = context.builtin_or_resolved_ty(id, parent_id,
701+
ty, location) {
699702
return Ok(ty);
700703
}
701704

src/ir/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ impl Type {
426426
parent_id: Option<ItemId>,
427427
ctx: &mut BindgenContext) -> Result<ParseResult<Self>, ParseError> {
428428
use clangll::*;
429-
if let Some(ty) = ctx.builtin_or_resolved_ty(parent_id, ty, location) {
429+
if let Some(ty) = ctx.builtin_or_resolved_ty(potential_id, parent_id,
430+
ty, location) {
430431
debug!("{:?} already resolved: {:?}", ty, location);
431432
return Ok(ParseResult::AlreadyResolved(ty));
432433
}

tests/expectations/class_with_inner_struct.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
2929
pub struct A {
3030
pub c: ::std::os::raw::c_uint,
3131
pub named_union: A__bindgen_ty_bindgen_id_9,
32-
pub __bindgen_anon_1: A__bindgen_ty_bindgen_id_14,
32+
pub __bindgen_anon_1: A__bindgen_ty_bindgen_id_13,
3333
}
3434
#[repr(C)]
3535
#[derive(Debug, Copy)]
@@ -61,17 +61,17 @@ impl Clone for A__bindgen_ty_bindgen_id_9 {
6161
}
6262
#[repr(C)]
6363
#[derive(Debug, Copy)]
64-
pub struct A__bindgen_ty_bindgen_id_14 {
64+
pub struct A__bindgen_ty_bindgen_id_13 {
6565
pub d: __BindgenUnionField<::std::os::raw::c_int>,
6666
pub bindgen_union_field: u32,
6767
}
6868
#[test]
69-
fn bindgen_test_layout_A__bindgen_ty_bindgen_id_14() {
70-
assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_14>() , 4usize);
71-
assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_14>() ,
69+
fn bindgen_test_layout_A__bindgen_ty_bindgen_id_13() {
70+
assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_13>() , 4usize);
71+
assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_13>() ,
7272
4usize);
7373
}
74-
impl Clone for A__bindgen_ty_bindgen_id_14 {
74+
impl Clone for A__bindgen_ty_bindgen_id_13 {
7575
fn clone(&self) -> Self { *self }
7676
}
7777
#[test]
@@ -121,57 +121,57 @@ pub enum StepSyntax {
121121
#[derive(Debug, Copy)]
122122
pub struct C {
123123
pub d: ::std::os::raw::c_uint,
124-
pub __bindgen_anon_1: C__bindgen_ty_bindgen_id_31,
124+
pub __bindgen_anon_1: C__bindgen_ty_bindgen_id_30,
125125
}
126126
#[repr(C)]
127127
#[derive(Debug, Copy)]
128-
pub struct C__bindgen_ty_bindgen_id_31 {
129-
pub mFunc: __BindgenUnionField<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32>,
130-
pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43>,
128+
pub struct C__bindgen_ty_bindgen_id_30 {
129+
pub mFunc: __BindgenUnionField<C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_31>,
130+
pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_41>,
131131
pub bindgen_union_field: [u32; 4usize],
132132
}
133133
#[repr(C)]
134134
#[derive(Debug, Copy)]
135-
pub struct C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32 {
135+
pub struct C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_31 {
136136
pub mX1: f32,
137137
pub mY1: f32,
138138
pub mX2: f32,
139139
pub mY2: f32,
140140
}
141141
#[test]
142-
fn bindgen_test_layout_C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32() {
143-
assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32>()
142+
fn bindgen_test_layout_C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_31() {
143+
assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_31>()
144144
, 16usize);
145-
assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32>()
145+
assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_31>()
146146
, 4usize);
147147
}
148-
impl Clone for C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_32 {
148+
impl Clone for C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_31 {
149149
fn clone(&self) -> Self { *self }
150150
}
151151
#[repr(C)]
152152
#[derive(Debug, Copy)]
153-
pub struct C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43 {
153+
pub struct C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_41 {
154154
pub mStepSyntax: StepSyntax,
155155
pub mSteps: ::std::os::raw::c_uint,
156156
}
157157
#[test]
158-
fn bindgen_test_layout_C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43() {
159-
assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43>()
158+
fn bindgen_test_layout_C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_41() {
159+
assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_41>()
160160
, 8usize);
161-
assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43>()
161+
assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_41>()
162162
, 4usize);
163163
}
164-
impl Clone for C__bindgen_ty_bindgen_id_31__bindgen_ty_bindgen_id_43 {
164+
impl Clone for C__bindgen_ty_bindgen_id_30__bindgen_ty_bindgen_id_41 {
165165
fn clone(&self) -> Self { *self }
166166
}
167167
#[test]
168-
fn bindgen_test_layout_C__bindgen_ty_bindgen_id_31() {
169-
assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_31>() ,
168+
fn bindgen_test_layout_C__bindgen_ty_bindgen_id_30() {
169+
assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_30>() ,
170170
16usize);
171-
assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_31>() ,
171+
assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_30>() ,
172172
4usize);
173173
}
174-
impl Clone for C__bindgen_ty_bindgen_id_31 {
174+
impl Clone for C__bindgen_ty_bindgen_id_30 {
175175
fn clone(&self) -> Self { *self }
176176
}
177177
#[repr(C)]

tests/expectations/jsval_layout_opaque.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub enum JSWhyMagic {
9494
#[derive(Debug, Copy)]
9595
pub struct jsval_layout {
9696
pub asBits: __BindgenUnionField<u64>,
97-
pub debugView: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_90>,
98-
pub s: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_97>,
97+
pub debugView: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_88>,
98+
pub s: __BindgenUnionField<jsval_layout__bindgen_ty_bindgen_id_92>,
9999
pub asDouble: __BindgenUnionField<f64>,
100100
pub asPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>,
101101
pub asWord: __BindgenUnionField<usize>,
@@ -104,20 +104,20 @@ pub struct jsval_layout {
104104
}
105105
#[repr(C)]
106106
#[derive(Debug, Copy)]
107-
pub struct jsval_layout__bindgen_ty_bindgen_id_90 {
107+
pub struct jsval_layout__bindgen_ty_bindgen_id_88 {
108108
pub _bitfield_1: u64,
109109
}
110110
#[test]
111-
fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_90() {
112-
assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_90>()
111+
fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_88() {
112+
assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_88>()
113113
, 8usize);
114-
assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_90>()
114+
assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_88>()
115115
, 8usize);
116116
}
117-
impl Clone for jsval_layout__bindgen_ty_bindgen_id_90 {
117+
impl Clone for jsval_layout__bindgen_ty_bindgen_id_88 {
118118
fn clone(&self) -> Self { *self }
119119
}
120-
impl jsval_layout__bindgen_ty_bindgen_id_90 {
120+
impl jsval_layout__bindgen_ty_bindgen_id_88 {
121121
#[inline]
122122
pub fn payload47(&self) -> u64 {
123123
unsafe {
@@ -150,36 +150,36 @@ impl jsval_layout__bindgen_ty_bindgen_id_90 {
150150
}
151151
#[repr(C)]
152152
#[derive(Debug, Copy)]
153-
pub struct jsval_layout__bindgen_ty_bindgen_id_97 {
154-
pub payload: jsval_layout__bindgen_ty_bindgen_id_97__bindgen_ty_bindgen_id_98,
153+
pub struct jsval_layout__bindgen_ty_bindgen_id_92 {
154+
pub payload: jsval_layout__bindgen_ty_bindgen_id_92__bindgen_ty_bindgen_id_93,
155155
}
156156
#[repr(C)]
157157
#[derive(Debug, Copy)]
158-
pub struct jsval_layout__bindgen_ty_bindgen_id_97__bindgen_ty_bindgen_id_98 {
158+
pub struct jsval_layout__bindgen_ty_bindgen_id_92__bindgen_ty_bindgen_id_93 {
159159
pub i32: __BindgenUnionField<i32>,
160160
pub u32: __BindgenUnionField<u32>,
161161
pub why: __BindgenUnionField<JSWhyMagic>,
162162
pub bindgen_union_field: u32,
163163
}
164164
#[test]
165-
fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_97__bindgen_ty_bindgen_id_98() {
166-
assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_97__bindgen_ty_bindgen_id_98>()
165+
fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_92__bindgen_ty_bindgen_id_93() {
166+
assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_92__bindgen_ty_bindgen_id_93>()
167167
, 4usize);
168-
assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_97__bindgen_ty_bindgen_id_98>()
168+
assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_92__bindgen_ty_bindgen_id_93>()
169169
, 4usize);
170170
}
171171
impl Clone for
172-
jsval_layout__bindgen_ty_bindgen_id_97__bindgen_ty_bindgen_id_98 {
172+
jsval_layout__bindgen_ty_bindgen_id_92__bindgen_ty_bindgen_id_93 {
173173
fn clone(&self) -> Self { *self }
174174
}
175175
#[test]
176-
fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_97() {
177-
assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_97>()
176+
fn bindgen_test_layout_jsval_layout__bindgen_ty_bindgen_id_92() {
177+
assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_bindgen_id_92>()
178178
, 4usize);
179-
assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_97>()
179+
assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_bindgen_id_92>()
180180
, 4usize);
181181
}
182-
impl Clone for jsval_layout__bindgen_ty_bindgen_id_97 {
182+
impl Clone for jsval_layout__bindgen_ty_bindgen_id_92 {
183183
fn clone(&self) -> Self { *self }
184184
}
185185
impl Clone for jsval_layout {

tests/expectations/union_template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
2929
pub struct NastyStruct<T> {
3030
pub mIsSome: bool,
3131
pub mStorage: NastyStruct__bindgen_ty_bindgen_id_6<T>,
32-
pub __bindgen_anon_1: NastyStruct__bindgen_ty_bindgen_id_12<T>,
32+
pub __bindgen_anon_1: NastyStruct__bindgen_ty_bindgen_id_11<T>,
3333
pub _phantom_0: ::std::marker::PhantomData<T>,
3434
}
3535
#[repr(C)]
@@ -42,7 +42,7 @@ pub struct NastyStruct__bindgen_ty_bindgen_id_6<T> {
4242
}
4343
#[repr(C)]
4444
#[derive(Debug, Copy, Clone)]
45-
pub struct NastyStruct__bindgen_ty_bindgen_id_12<T> {
45+
pub struct NastyStruct__bindgen_ty_bindgen_id_11<T> {
4646
pub wat: __BindgenUnionField<::std::os::raw::c_short>,
4747
pub wut: __BindgenUnionField<*mut ::std::os::raw::c_int>,
4848
pub bindgen_union_field: u64,

0 commit comments

Comments
 (0)