Skip to content

Fall back to opaque types rather than panicking on parse failure #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ impl<'ctx> BindgenContext<'ctx> {
for (id, ty, loc, parent_id) in typerefs {
let _resolved = {
let resolved = Item::from_ty(&ty, loc, parent_id, self)
.expect("What happened?");
.unwrap_or_else(|_| {
Item::new_opaque_type(self.next_item_id(), &ty, self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we want to leave a warning here or something.

});
let mut item = self.items.get_mut(&id).unwrap();

*item.kind_mut().as_type_mut().unwrap().kind_mut() =
Expand Down
9 changes: 5 additions & 4 deletions src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,11 @@ impl Item {
}
}

fn new_opaque_type(with_id: ItemId,
ty: &clang::Type,
ctx: &mut BindgenContext)
-> ItemId {
/// Construct a new opaque item type.
pub fn new_opaque_type(with_id: ItemId,
ty: &clang::Type,
ctx: &mut BindgenContext)
-> ItemId {
let ty = Opaque::from_clang_ty(ty);
let kind = ItemKind::Type(ty);
let parent = ctx.root_module();
Expand Down
14 changes: 8 additions & 6 deletions src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,12 +1093,14 @@ impl Type {
name = location.spelling();
}

let complex = CompInfo::from_ty(potential_id,
ty,
Some(location),
ctx)
.expect("C'mon");
TypeKind::Comp(complex)
if let Ok(complex) = CompInfo::from_ty(potential_id,
ty,
Some(location),
ctx) {
Copy link
Contributor

@emilio emilio Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps using match + a separate variable may look a bit cleaner?

let complex = CompInfo::from_ty(..);
match complex {
    Ok(complex) => TypeKind::Comp(complex),
    Err(..) => {
        warn!(...);
        return Ok(ParseResult::New(...));
    }
}

(or even without the variable)

Also, ditto re. warning.

TypeKind::Comp(complex)
} else {
return Ok(ParseResult::New(Opaque::from_clang_ty(ty), None));
}
}
CXCursor_TypeAliasTemplateDecl => {
debug!("TypeAliasTemplateDecl");
Expand Down