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

Bindgen gets parameter names wrong in callbacks #1535

Closed
dimbleby opened this issue Mar 9, 2019 · 3 comments
Closed

Bindgen gets parameter names wrong in callbacks #1535

dimbleby opened this issue Mar 9, 2019 · 3 comments

Comments

@dimbleby
Copy link
Contributor

dimbleby commented Mar 9, 2019

Input C/C++ Header

Input is the c-ares header ares.h.

Relevant fragment is:

CARES_EXTERN int ares_library_init_mem(int flags,
                                       void *(*amalloc)(size_t size),
                                       void (*afree)(void *ptr),
                                       void *(*arealloc)(void *ptr, size_t size));

Bindgen Invocation

bindgen --blacklist-type="__.*" \
        --blacklist-type="ares_socket_t" \
        --blacklist-type="fd_set" \
        --blacklist-type="hostent" \
        --blacklist-type="iovec" \
        --blacklist-type="sockaddr" \
        --blacklist-type="sa_family_t" \
        --blacklist-type="socklen_t" \
        --blacklist-type="timeval" \
        --whitelist-function="ares.*" \
        --whitelist-type="ares.*" \
        --whitelist-type="apattern" \
        --opaque-type="in_addr_t" \
        --no-layout-tests \
        --output=src/ffi.rs \
        c-ares/ares.h

Actual Results

Output like this:

extern "C" {
    pub fn ares_library_init_mem(
        flags: ::std::os::raw::c_int,
        amalloc: ::std::option::Option<
            unsafe extern "C" fn(flags: usize) -> *mut ::std::os::raw::c_void,
        >,
        afree: ::std::option::Option<unsafe extern "C" fn(flags: *mut ::std::os::raw::c_void)>,
        arealloc: ::std::option::Option<
            unsafe extern "C" fn(
                flags: *mut ::std::os::raw::c_void,
                amalloc: usize,
            ) -> *mut ::std::os::raw::c_void,
        >,
    ) -> ::std::os::raw::c_int;
}

Expected Results

As you can see, the names of the parameters for the callback functions are wrong - they should be size, then ptr, then ptr and size. But instead they are flags, then flags, and then flags and amalloc.

That is, the parameter names for the surrounding function have been injected into the callbacks!

This is a regression at 1092778 - prior to that, the output was as expected. @flowbish.

@flowbish
Copy link
Contributor

flowbish commented Mar 9, 2019

I'll take a look at this.

flowbish added a commit to flowbish/rust-bindgen that referenced this issue Mar 9, 2019
flowbish added a commit to flowbish/rust-bindgen that referenced this issue Mar 9, 2019
@emilio
Copy link
Contributor

emilio commented Mar 10, 2019

Thanks @flowbish!

flowbish added a commit to flowbish/rust-bindgen that referenced this issue Mar 10, 2019
emilio added a commit that referenced this issue Mar 11, 2019
Fix issue #1535: use correct names for function parameters in function pointer arguments.
@emilio
Copy link
Contributor

emilio commented Mar 11, 2019

Fixed by #1536. Thank again @flowbish :)

@emilio emilio closed this as completed Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants