Skip to content

Commit b1a1ebc

Browse files
committed
ir: Fall back to get the cursors from the type if we find no param decls.
It seems libclang sometimes doesn't expose the right paramdecl cursors. This should be reported upstream, but it's easy enough to workaround. It loses the parameter names which is a bit unfortunate but... Fixes #1778
1 parent fcc1096 commit b1a1ebc

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/ir/function.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn args_from_ty_and_cursor(
311311
cursor: &clang::Cursor,
312312
ctx: &mut BindgenContext,
313313
) -> Vec<(Option<String>, TypeId)> {
314-
let cursor_args = cursor.args().unwrap().into_iter();
314+
let cursor_args = cursor.args().unwrap_or_default().into_iter();
315315
let type_args = ty.args().unwrap_or_default().into_iter();
316316

317317
// Argument types can be found in either the cursor or the type, but argument names may only be
@@ -421,7 +421,16 @@ impl FunctionSig {
421421
}
422422
CXChildVisit_Continue
423423
});
424-
args
424+
425+
if args.is_empty() {
426+
// FIXME(emilio): Sometimes libclang doesn't expose the
427+
// right AST for functions tagged as stdcall and such...
428+
//
429+
// https://bugs.llvm.org/show_bug.cgi?id=45919
430+
args_from_ty_and_cursor(&ty, &cursor, ctx)
431+
} else {
432+
args
433+
}
425434
}
426435
};
427436

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
9+
10+
pub type PFN_VIGEM_X360_NOTIFICATION = ::std::option::Option<
11+
unsafe extern "C" fn(
12+
arg1: *mut ::std::os::raw::c_void,
13+
arg2: *mut ::std::os::raw::c_void,
14+
arg3: ::std::os::raw::c_uchar,
15+
arg4: ::std::os::raw::c_uchar,
16+
arg5: ::std::os::raw::c_uchar,
17+
arg6: *mut ::std::os::raw::c_void,
18+
),
19+
>;

tests/expectations/tests/objc_property_fnptr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ pub trait IFoo: Sized + std::ops::Deref {
4646
unsafe fn setFunc_(
4747
self,
4848
func: ::std::option::Option<
49-
unsafe extern "C" fn() -> ::std::os::raw::c_int,
49+
unsafe extern "C" fn(
50+
arg1: ::std::os::raw::c_char,
51+
arg2: ::std::os::raw::c_short,
52+
arg3: f32,
53+
) -> ::std::os::raw::c_int,
5054
>,
5155
) where
5256
<Self as std::ops::Deref>::Target: objc::Message + Sized,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
typedef
2+
void __stdcall
3+
EVT_VIGEM_X360_NOTIFICATION(
4+
void* Client,
5+
void* Target,
6+
unsigned char LargeMotor,
7+
unsigned char SmallMotor,
8+
unsigned char LedNumber,
9+
void* UserData
10+
);
11+
12+
typedef EVT_VIGEM_X360_NOTIFICATION *PFN_VIGEM_X360_NOTIFICATION;

0 commit comments

Comments
 (0)