diff options
-rw-r--r-- | src/parser.rs | 11 | ||||
-rw-r--r-- | tests/func_ptr.rs | 17 | ||||
-rw-r--r-- | tests/headers/func_ptr.h | 1 | ||||
-rw-r--r-- | tests/headers/func_ptr_in_struct.h | 3 |
4 files changed, 29 insertions, 3 deletions
diff --git a/src/parser.rs b/src/parser.rs index 5b06b0e9..e26ce4f5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -167,9 +167,14 @@ fn conv_ptr_ty(ctx: &mut ClangParserCtx, ty: &cx::Type, cursor: &Cursor, layout: let ret_ty = ty.ret_type(); let decl = ty.declaration(); return if ret_ty.kind() != CXType_Invalid { - let args_lst = ty.arg_types().iter().map(|arg| { - ("".to_string(), conv_ty(ctx, arg, cursor)) - }).collect(); + let mut args_lst = vec!(); + cursor.visit(|c, _| { + if c.kind() == CXCursor_ParmDecl { + args_lst.push((c.spelling(), conv_ty(ctx, &c.cur_type(), c))); + } + CXChildVisit_Continue + }); + let ret_ty = box conv_ty(ctx, &ret_ty, cursor); let abi = get_abi(ty.call_conv()); diff --git a/tests/func_ptr.rs b/tests/func_ptr.rs new file mode 100644 index 00000000..7851c4ff --- /dev/null +++ b/tests/func_ptr.rs @@ -0,0 +1,17 @@ +extern crate bindgen; +extern crate regex; +extern crate syntax; + +mod util; + +#[test] +fn test_func_ptr() { + let output = util::generate_unpretty_output("tests/headers/func_ptr.h"); + assert_eq!(output, r##"extern "C" { pub static mut foo: ::std::option::Option<extern "C" fn(x: ::libc::c_int, y: ::libc::c_int) -> ::libc::c_int>; }"##); +} + +#[test] +fn test_func_ptr_in_struct() { + let output = util::generate_unpretty_output("tests/headers/func_ptr_in_struct.h"); + assert_eq!(output, r##"#[repr(C)] #[deriving(Copy)] pub struct Struct_Foo { pub bar: ::std::option::Option<extern "C" fn(x: ::libc::c_int, y: ::libc::c_int) -> Enum_baz>, } extern "C" { }"##); +} diff --git a/tests/headers/func_ptr.h b/tests/headers/func_ptr.h new file mode 100644 index 00000000..a4662f3d --- /dev/null +++ b/tests/headers/func_ptr.h @@ -0,0 +1 @@ +int (*foo) (int x, int y); diff --git a/tests/headers/func_ptr_in_struct.h b/tests/headers/func_ptr_in_struct.h new file mode 100644 index 00000000..8e9bf60c --- /dev/null +++ b/tests/headers/func_ptr_in_struct.h @@ -0,0 +1,3 @@ +struct Foo { + enum baz (*bar) (int x, int y); +}; |