Skip to content

Commit 8a51860

Browse files
michaelwunox
authored andcommitted
Recurse into unexposed decls
This fixes functions that use extern "C".
1 parent 6e33fbe commit 8a51860

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

src/parser.rs

+3
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ fn visit_top<'r>(cursor: &Cursor,
498498
}
499499

500500
match cursor.kind() {
501+
CXCursor_UnexposedDecl => {
502+
return CXChildVisit_Recurse;
503+
}
501504
CXCursor_StructDecl | CXCursor_UnionDecl => {
502505
fwd_decl(ctx, cursor, |ctx_| {
503506
let decl = decl_name(ctx_, cursor);

tests/headers/extern.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern "C" {
2+
#include "func_proto.h"
3+
}

tests/support.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ impl Logger for TestLogger {
2525

2626
pub fn generate_bindings(filename: &str) -> Result<Vec<P<ast::Item>>, ()> {
2727
let mut options:BindgenOptions = Default::default();
28+
if filename.ends_with("hpp") {
29+
options.clang_args.push("-std=c++11".to_string());
30+
}
2831
options.clang_args.push(filename.to_string());
2932

3033
let logger = TestLogger;

tests/test_extern.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use support::assert_bind_eq;
2+
3+
#[test]
4+
fn extern_c_in_hpp() {
5+
assert_bind_eq("headers/extern.hpp", "
6+
pub type foo = extern \"C\" fn(bar: ::libc::c_int) -> ::libc::c_int;
7+
");
8+
}

tests/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod support;
99
// Unused until we can generate code for tests
1010
//mod test_cmath;
1111
mod test_decl;
12+
mod test_extern;
1213
mod test_func;
1314
mod test_struct;
1415
mod test_union;

0 commit comments

Comments
 (0)