rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Inappropriate generated type for function-returning-function

Open cole-miller opened this issue 1 year ago • 1 comments

Input C/C++ Header

void (*(*xDlSym)(const char *))(void);

Bindgen Invocation

$ bindgen input.h

Actual Results

/* automatically generated by rust-bindgen 0.69.1 */

extern "C" {
    pub static mut xDlSym: ::std::option::Option<
        unsafe extern "C" fn(
            arg3: *const ::std::os::raw::c_char,
        ) -> ::std::option::Option<
            unsafe extern "C" fn(
                arg3: *const ::std::os::raw::c_char,
            ),
        >,
    >;
}

Expected Results

extern "C" {
    pub static mut xDlSym: ::std::option::Option<
        unsafe extern "C" fn(
            arg3: *const ::std::os::raw::c_char,
        ) -> ::std::option::Option<
            unsafe extern "C" fn(
-               arg3: *const ::std::os::raw::c_char,
            ),
        >,
    >;
}

The original C signature is hard to read: it describes a function pointer xDlSym that takes a single const char * argument and returns another function pointer of type void (*)(void). But in the bindgen-generated output, the returned function pointer has the inappropriate type void (*)(const char *) instead.

This affects the public API of libsqlite3-sys here; the reproducer is minimized from that situation.

cole-miller avatar Jan 09 '24 20:01 cole-miller

Interesting. We're reading stuff from libclang, but IIRC there were some quirks with how we get the right function type.

emilio avatar Jan 12 '24 22:01 emilio