diff options
author | Rémy HUBSCHER <rhubscher@mozilla.com> | 2016-11-04 17:05:23 +0100 |
---|---|---|
committer | Rémy HUBSCHER <rhubscher@mozilla.com> | 2016-11-17 16:04:51 +0100 |
commit | e65cd9bf47f52c13522b984426e26b948de9dbe7 (patch) | |
tree | 7a15b8fd8602a390251653d1dfef3c682a0e6b48 /libbindgen/src | |
parent | 3761ada615983a20456370dacbbb41628c69650e (diff) |
Attempt to fix #130 — clang::Cursor::args should return an Option<Vec<Cursor>>
Diffstat (limited to 'libbindgen/src')
-rw-r--r-- | libbindgen/src/clang.rs | 26 | ||||
-rw-r--r-- | 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 637823ea..6c95b22f 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<Cursor> { + pub fn args(&self) -> Option<Vec<Cursor>> { + // 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 eacb6c0e..60bd1e5b 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(); |