cbindgen
cbindgen copied to clipboard
Support variadic arguments (`args: ...` syntax)
There are many cases in Relibc where Rust functions are wrapped in C functions only to make them use ... syntax.
Related Rust RFC: https://github.com/rust-lang/rfcs/blob/master/text/2137-variadic.md
This shouldn't be hard to implement, if you want to give it a shot I'm happy to mentor :)
How to implement?
Given this code:
#[no_mangle]
pub unsafe extern "C" fn func(fixed: u32, mut args: ...) {
let x: u8 = args.arg();
let y: u16 = args.arg();
let z: u32 = args.arg();
println!("{} {} {} {}", fixed, x, y, z);
}
Right now cbindgen says:
ERROR: Cannot use fn t::func (Unsupported type: Verbatim(TokenStream [Punct { op: '.', spacing: Joint }, Punct { op: '.', spacing: Joint }, Punct { op: '.', spacing: Alone }]))
So basically the code in Function::load that parses the signature needs to be taught about that pattern, and flag the function as variadic rather than treating it as an argument. Then use that flag to generate the appropriate C/C++ code.
Given this code:
#[no_mangle] pub unsafe extern "C" fn func(fixed: u32, mut args: ...) { let x: u8 = args.arg(); let y: u16 = args.arg(); let z: u32 = args.arg(); println!("{} {} {} {}", fixed, x, y, z); }Right now cbindgen says:
ERROR: Cannot use fn t::func (Unsupported type: Verbatim(TokenStream [Punct { op: '.', spacing: Joint }, Punct { op: '.', spacing: Joint }, Punct { op: '.', spacing: Alone }]))So basically the code in
Function::loadthat parses the signature needs to be taught about that pattern, and flag the function as variadic rather than treating it as an argument. Then use that flag to generate the appropriate C/C++ code.
can you fix it?
I mean, I could, but I have no real incentive to right now and cbindgen is just a free-time kinda thing. So I'd rather let other people help with the project and get introduced to it, specially since this is not particularly super-complicated.
Unsupported type:
Why say this? I create a testcase and it's do nothing
I know nothing about cbindgen, hard for me to fix it