From 4d2ba9dba601db91c0b3bddcee990dd0e75e076b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 21 Jul 2017 14:50:46 +0200 Subject: [PATCH 1/2] ir: We really need to traverse all edges for the used template parameter analysis to be sound. --- src/ir/context.rs | 2 +- src/ir/traversal.rs | 28 ---------------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index ec79577f3f..d74d3ae01a 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -219,7 +219,7 @@ impl<'ctx, 'gen> WhitelistedItems<'ctx, 'gen> where R: IntoIterator, { let predicate = if ctx.options().whitelist_recursively { - traversal::codegen_edges + traversal::all_edges } else { traversal::no_edges }; diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs index d4b081f5ff..842da61e34 100644 --- a/src/ir/traversal.rs +++ b/src/ir/traversal.rs @@ -201,34 +201,6 @@ pub fn all_edges(_: &BindgenContext, _: Edge) -> bool { true } -/// A `TraversalPredicate` implementation that only follows edges to items that -/// are enabled for code generation. This lets us skip considering items for -/// which we won't generate any bindings to. -pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { - let cc = &ctx.options().codegen_config; - match edge.kind { - EdgeKind::Generic => ctx.resolve_item(edge.to).is_enabled_for_codegen(ctx), - - // We statically know the kind of item that non-generic edges can point - // to, so we don't need to actually resolve the item and check - // `Item::is_enabled_for_codegen`. - EdgeKind::TemplateParameterDefinition | - EdgeKind::TemplateArgument | - EdgeKind::TemplateDeclaration | - EdgeKind::BaseMember | - EdgeKind::Field | - EdgeKind::InnerType | - EdgeKind::FunctionReturn | - EdgeKind::FunctionParameter | - EdgeKind::VarType | - EdgeKind::TypeReference => cc.types, - EdgeKind::InnerVar => cc.vars, - EdgeKind::Method => cc.methods, - EdgeKind::Constructor => cc.constructors, - EdgeKind::Destructor => cc.destructors, - } -} - /// A `TraversalPredicate` implementation that never follows any edges, and /// therefore traversals using this predicate will only visit the traversal's /// roots. From ba9298d41db350010b58ea0b9cfffd1c0f1e4ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 21 Jul 2017 14:55:12 +0200 Subject: [PATCH 2/2] Test. --- tests/expectations/tests/issue-833.rs | 10 ++++++++++ tests/headers/issue-833.hpp | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/expectations/tests/issue-833.rs create mode 100644 tests/headers/issue-833.hpp diff --git a/tests/expectations/tests/issue-833.rs b/tests/expectations/tests/issue-833.rs new file mode 100644 index 0000000000..9de7c64f01 --- /dev/null +++ b/tests/expectations/tests/issue-833.rs @@ -0,0 +1,10 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + +#[repr(C)] pub struct nsTArray { pub hdr: *const T } + +extern "C" { + pub fn func() -> *mut nsTArray<::std::os::raw::c_int>; +} diff --git a/tests/headers/issue-833.hpp b/tests/headers/issue-833.hpp new file mode 100644 index 0000000000..ea0d2add71 --- /dev/null +++ b/tests/headers/issue-833.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: --generate functions --whitelist-function func --raw-line "#[repr(C)] pub struct nsTArray { pub hdr: *const T }" + +template +class nsTArray { + T* mHeader; +}; + +extern "C" nsTArray* func();