Skip to content

Commit 1a8a2ac

Browse files
author
bors-servo
authored
Auto merge of #207 - Natim:130-cursor-args-return-vector, r=emilio
clang::Cursor::args should return an Option<Vec<Cursor>> Attempt to fix #130
2 parents c48f835 + 3f0f868 commit 1a8a2ac

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

libbindgen/src/clang.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,26 @@ impl Cursor {
420420

421421
/// Given that this cursor's referent is a function, return cursors to its
422422
/// parameters.
423-
pub fn args(&self) -> Vec<Cursor> {
423+
pub fn args(&self) -> Option<Vec<Cursor>> {
424+
// XXX: We might want to use and keep num_args
425+
// match self.kind() {
426+
// CXCursor_FunctionDecl |
427+
// CXCursor_CXXMethod => {
424428
unsafe {
425-
let num = self.num_args().expect("expected value, got none") as u32;
426-
let mut args = vec![];
427-
for i in 0..num {
428-
args.push(Cursor {
429-
x: clang_Cursor_getArgument(self.x, i as c_uint),
430-
});
429+
let w = clang_Cursor_getNumArguments(self.x);
430+
if w == -1 {
431+
None
432+
} else {
433+
let num = w as u32;
434+
435+
let mut args = vec![];
436+
for i in 0..num {
437+
args.push(Cursor {
438+
x: clang_Cursor_getArgument(self.x, i as c_uint),
439+
});
440+
}
441+
Some(args)
431442
}
432-
args
433443
}
434444
}
435445

libbindgen/src/ir/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl FunctionSig {
150150
CXCursor_CXXMethod => {
151151
// For CXCursor_FunctionDecl, cursor.args() is the reliable way
152152
// to get parameter names and types.
153-
cursor.args()
153+
cursor.args().expect("It cannot be None because we are in a method/function")
154154
.iter()
155155
.map(|arg| {
156156
let arg_ty = arg.cur_type();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct VariadicFunctionObject<T> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<T>,
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
template <typename T>
3+
class VariadicFunctionObject {
4+
public:
5+
int add_em_up(T count,...);
6+
};

0 commit comments

Comments
 (0)