Skip to content

Bindgen gets parameter names wrong in callbacks #1535

Closed
@dimbleby

Description

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.

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions