Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variadic arguments (args: ... syntax) #376

Closed
mati865 opened this issue Aug 9, 2019 · 7 comments · Fixed by #805
Closed

Support variadic arguments (args: ... syntax) #376

mati865 opened this issue Aug 9, 2019 · 7 comments · Fixed by #805

Comments

@mati865
Copy link

mati865 commented Aug 9, 2019

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

@emilio
Copy link
Collaborator

emilio commented Aug 9, 2019

This shouldn't be hard to implement, if you want to give it a shot I'm happy to mentor :)

@lygstate
Copy link

lygstate commented Oct 9, 2020

How to implement?

@emilio
Copy link
Collaborator

emilio commented Oct 9, 2020

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.

@lygstate
Copy link

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.

can you fix it?

@emilio
Copy link
Collaborator

emilio commented Oct 15, 2020

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.

@lygstate
Copy link

Unsupported type:

Why say this? I create a testcase and it's do nothing

@lygstate
Copy link

I know nothing about cbindgen, hard for me to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants