From e65cd9bf47f52c13522b984426e26b948de9dbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Fri, 4 Nov 2016 17:05:23 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Attempt=20to=20fix=20#130=20=E2=80=94=20cla?= =?UTF-8?q?ng::Cursor::args=20should=20return=20an=20Option>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libbindgen/src/clang.rs | 26 ++++++++++++++++++-------- libbindgen/src/ir/function.rs | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs index 637823ead8..6c95b22f3c 100644 --- a/libbindgen/src/clang.rs +++ b/libbindgen/src/clang.rs @@ -420,16 +420,26 @@ impl Cursor { /// Given that this cursor's referent is a function, return cursors to its /// parameters. - pub fn args(&self) -> Vec { + pub fn args(&self) -> Option> { + // XXX: We might want to use and keep num_args + // match self.kind() { + // CXCursor_FunctionDecl | + // CXCursor_CXXMethod => { unsafe { - let num = self.num_args().expect("expected value, got none") as u32; - let mut args = vec![]; - for i in 0..num { - args.push(Cursor { - x: clang_Cursor_getArgument(self.x, i as c_uint), - }); + let w = clang_Cursor_getNumArguments(self.x); + if w == -1 { + None + } else { + let num = w as u32; + + let mut args = vec![]; + for i in 0..num { + args.push(Cursor { + x: clang_Cursor_getArgument(self.x, i as c_uint), + }); + } + Some(args) } - args } } diff --git a/libbindgen/src/ir/function.rs b/libbindgen/src/ir/function.rs index eacb6c0ea8..60bd1e5b75 100644 --- a/libbindgen/src/ir/function.rs +++ b/libbindgen/src/ir/function.rs @@ -150,7 +150,7 @@ impl FunctionSig { CXCursor_CXXMethod => { // For CXCursor_FunctionDecl, cursor.args() is the reliable way // to get parameter names and types. - cursor.args() + cursor.args().expect("It cannot be None because we are in a method/function") .iter() .map(|arg| { let arg_ty = arg.cur_type(); From 3f0f86810b855d20dfc39655f336ba814d169281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Fri, 18 Nov 2016 19:15:16 +0100 Subject: [PATCH 2/2] Add a test --- .../expectations/tests/variadic_template_function.rs | 12 ++++++++++++ .../tests/headers/variadic_template_function.hpp | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 libbindgen/tests/expectations/tests/variadic_template_function.rs create mode 100644 libbindgen/tests/headers/variadic_template_function.hpp diff --git a/libbindgen/tests/expectations/tests/variadic_template_function.rs b/libbindgen/tests/expectations/tests/variadic_template_function.rs new file mode 100644 index 0000000000..cd99df960d --- /dev/null +++ b/libbindgen/tests/expectations/tests/variadic_template_function.rs @@ -0,0 +1,12 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct VariadicFunctionObject { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData, +} diff --git a/libbindgen/tests/headers/variadic_template_function.hpp b/libbindgen/tests/headers/variadic_template_function.hpp new file mode 100644 index 0000000000..4942d8f024 --- /dev/null +++ b/libbindgen/tests/headers/variadic_template_function.hpp @@ -0,0 +1,6 @@ + +template +class VariadicFunctionObject { +public: + int add_em_up(T count,...); +};