Skip to content

Commit 801179c

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 79407f3 commit 801179c

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/ir/context.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,22 +467,22 @@ impl<'ctx> BindgenContext<'ctx> {
467467
/// };
468468
/// ```
469469
fn build_template_wrapper(&mut self,
470+
with_id: ItemId,
470471
wrapping: ItemId,
471472
parent_id: ItemId,
472473
ty: &clang::Type,
473474
location: clang::Cursor) -> ItemId {
474475
use clangll::*;
475476
let mut args = vec![];
476477
let mut found_invalid_template_ref = false;
477-
let self_id = ItemId::next();
478478
location.visit(|c, _| {
479479
if c.kind() == CXCursor_TemplateRef &&
480480
c.cur_type().kind() == CXType_Invalid {
481481
found_invalid_template_ref = true;
482482
}
483483
if c.kind() == CXCursor_TypeRef {
484484
let new_ty =
485-
Item::from_ty_or_ref(c.cur_type(), Some(*c), Some(self_id), self);
485+
Item::from_ty_or_ref(c.cur_type(), Some(*c), Some(with_id), self);
486486
args.push(new_ty);
487487
}
488488
CXChildVisit_Continue
@@ -528,17 +528,18 @@ impl<'ctx> BindgenContext<'ctx> {
528528
let name = ty.spelling();
529529
let name = if name.is_empty() { None } else { Some(name) };
530530
let ty = Type::new(name, ty.fallible_layout().ok(), type_kind, ty.is_const());
531-
Item::new(self_id, None, None, parent_id, ItemKind::Type(ty))
531+
Item::new(with_id, None, None, parent_id, ItemKind::Type(ty))
532532
};
533533

534534
// Bypass all the validations in add_item explicitly.
535-
self.items.insert(self_id, item);
536-
self_id
535+
self.items.insert(with_id, item);
536+
with_id
537537
}
538538

539539
/// Looks up for an already resolved type, either because it's builtin, or
540540
/// because we already have it in the map.
541541
pub fn builtin_or_resolved_ty(&mut self,
542+
with_id: ItemId,
542543
parent_id: Option<ItemId>,
543544
ty: &clang::Type,
544545
location: Option<clang::Cursor>) -> Option<ItemId> {
@@ -567,6 +568,7 @@ impl<'ctx> BindgenContext<'ctx> {
567568
if let Some(id) = id {
568569
debug!("Already resolved ty {:?}, {:?}, {:?} {:?}",
569570
id, declaration, ty, location);
571+
570572
// If the declaration existed, we *might* be done, but it's not
571573
// the case for class templates, where the template arguments
572574
// may vary.
@@ -582,11 +584,12 @@ impl<'ctx> BindgenContext<'ctx> {
582584
*ty != canonical_declaration.cur_type() &&
583585
location.is_some() && parent_id.is_some() {
584586
return Some(
585-
self.build_template_wrapper(id, parent_id.unwrap(), ty,
587+
self.build_template_wrapper(with_id, id,
588+
parent_id.unwrap(), ty,
586589
location.unwrap()));
587590
}
588591

589-
return Some(self.build_ty_wrapper(id, parent_id, ty));
592+
return Some(self.build_ty_wrapper(with_id, id, parent_id, ty));
590593
}
591594
}
592595

@@ -602,19 +605,19 @@ impl<'ctx> BindgenContext<'ctx> {
602605
// We should probably make the constness tracking separate, so it doesn't
603606
// bloat that much, but hey, we already bloat the heck out of builtin types.
604607
fn build_ty_wrapper(&mut self,
608+
with_id: ItemId,
605609
wrapped_id: ItemId,
606610
parent_id: Option<ItemId>,
607611
ty: &clang::Type) -> ItemId {
608-
let id = ItemId::next();
609612
let spelling = ty.spelling();
610613
let is_const = ty.is_const();
611614
let layout = ty.fallible_layout().ok();
612615
let type_kind = TypeKind::ResolvedTypeRef(wrapped_id);
613616
let ty = Type::new(Some(spelling), layout, type_kind, is_const);
614-
let item = Item::new(id, None, None,
617+
let item = Item::new(with_id, None, None,
615618
parent_id.unwrap_or(self.current_module), ItemKind::Type(ty));
616619
self.add_builtin_item(item);
617-
id
620+
with_id
618621
}
619622

620623
fn build_builtin_ty(&mut self,

src/ir/item.rs

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

720-
if let Some(ty) = context.builtin_or_resolved_ty(parent_id, &ty, location) {
720+
if let Some(ty) = context.builtin_or_resolved_ty(potential_id,
721+
parent_id, &ty,
722+
location) {
721723
debug!("{:?} already resolved: {:?}", ty, location);
722724
return ty;
723725
}
@@ -779,7 +781,8 @@ impl ClangItemParser for Item {
779781
context.replace(replaced, id);
780782
}
781783

782-
if let Some(ty) = context.builtin_or_resolved_ty(parent_id, ty, location) {
784+
if let Some(ty) = context.builtin_or_resolved_ty(id, parent_id,
785+
ty, location) {
783786
return Ok(ty);
784787
}
785788

src/ir/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ impl Type {
471471
parent_id: Option<ItemId>,
472472
ctx: &mut BindgenContext) -> Result<ParseResult<Self>, ParseError> {
473473
use clangll::*;
474-
if let Some(ty) = ctx.builtin_or_resolved_ty(parent_id, ty, location) {
474+
if let Some(ty) = ctx.builtin_or_resolved_ty(potential_id, parent_id,
475+
ty, location) {
475476
debug!("{:?} already resolved: {:?}", ty, location);
476477
return Ok(ParseResult::AlreadyResolved(ty));
477478
}

0 commit comments

Comments
 (0)