An attribute on C callback function leads to wrong bindings
If in C code I have this line:
typedef void (mi_cdecl mi_output_fun)(const char* msg, void* arg);
and this function:
mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
then the generated binding is:
extern "C" {
pub fn mi_stats_print_out(
out: ::core::option::Option<unsafe extern "C" fn()>,
arg: *mut libc::c_void,
);
}
All arguments are lost.
To fix this, I need to remove mi_cdecl from the callback function:
typedef void mi_output_fun(const char* msg, void* arg);
and then generated bindings are reasonable:
pub type mi_output_fun =
::core::option::Option<unsafe extern "C" fn(msg: *const libc::c_char, arg: *mut libc::c_void)>;
extern "C" {
pub fn mi_stats_print_out(out: mi_output_fun, arg: *mut libc::c_void);
}
The code is here.
If there's a chance to come up with a standalone test-case that doesn't involve the whole allocator it'd be really appreciated. I think it shouldn't be hard, I can try to give it a shot later, but I'm pretty swamped this week...
Also clang version involved would be helpful.
Clang 9.0 on Windows. (On Linux bindgen fails with "cannot find libclang.so..." after installing LLVM with default .sh, but that is a separate issue).
Only this wrapper and build script part are needed to reproduce.
A wrapper is not great because it depends on a bunch of other stuff. https://github.com/rust-lang/rust-bindgen/blob/master/CONTRIBUTING.md#using-creduce-to-minimize-test-cases has some instructions to get a more reduced test-case but I can give it a shot later.
@buybackoff have you had time to find a minimal example?
@buybackoff have you had time to find a minimal example?
No, I fixed my issue as described and it's no longer an issue for me.