Skip to content

use of VOID typedef results in bindings that return c_void #2377

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

Closed
AdamGlass opened this issue Dec 30, 2022 · 2 comments · Fixed by #2379
Closed

use of VOID typedef results in bindings that return c_void #2377

AdamGlass opened this issue Dec 30, 2022 · 2 comments · Fixed by #2379

Comments

@AdamGlass
Copy link

Input C/C++ Header

void this_api_returns_nothing(void);

typedef void VOID;

VOID this_api_also_returns_nothing(VOID);

Bindgen Invocation

bindgen::Builder::default()
    .header("input.h")
    .generate()
    .unwrap()

Actual Results

/* automatically generated by rust-bindgen 0.63.0 */

extern "C" {
    pub fn this_api_returns_nothing();
}
pub type VOID = ::std::os::raw::c_void;
extern "C" {
    pub fn this_api_also_returns_nothing() -> VOID;
}

### Expected Results
extern "C" {
    pub fn this_api_returns_nothing();
}

extern "C" {
    pub fn this_api_also_returns_nothing();
}

Basically the codebase has a typedef for VOID which it uses instead of void..  This results in functions that return c_void which is only intended for pointers.  Any ideas on how to solve?
@AdamGlass
Copy link
Author

I have to acknowledge that commenting out the typedef and replacing it with '#define VOID void' works just fine. It's not a great out of the box solution given the typedef is in the shipping headers.

emilio added a commit that referenced this issue Jan 2, 2023
And reuse a bit more code.

Should fix #2377, but needs a test (can't run tests atm).
@emilio
Copy link
Contributor

emilio commented Jan 2, 2023

This seems like a plain oversight. The code we have to detect whether the return type of a function is void doesn't look through type aliases. #2379 is a potential fix, but needs a test and I can't write it right now.

pvdrz added a commit that referenced this issue Jan 6, 2023
* codegen: Look through typedefs to detect void return type.

And reuse a bit more code.

Should fix #2377, but needs a test (can't run tests atm).

* Add tests

* Run rustfmt

* Update changelog

Co-authored-by: Christian Poveda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants