rust-lang / rust-lang/rust-bindgen

Inappropriate generated type for function-returning-function

Open
#2,713 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal input.h declaration and run the bindgen invocation shown in the issue to reproduce the generated Rust type. Compare the returned function pointer's parameter list with the expected output and add coverage for this function-returning-function case; done when the generated binding matches the expected signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.