rust-lang / rust-lang/rust-bindgen

Incorrect wrapper generated by `--wrap-static-fns --c-naming`

Open
#2,522 0 comments 0 reactions 1 assignee View on GitHub

@pvdrz is already working on this.

Since May 6, 2023.

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

Description

Input C/C++ Header
struct test {};

static inline int do_stuff(struct test s) {
    return 42;
}
Bindgen Invocation
$ bindgen --experimental --wrap-static-fns --wrap-static-fns-path wrapper.c --c-naming test.h > test.rs
$ gcc -c wrapper.c
Actual Results

wrapper.c:

#include "test.h"

// Static wrappers

int do_stuff__extern(struct struct_test s) { return do_stuff(s); }

gcc error:

wrapper.c:5:29: warning: ‘struct struct_test’ declared inside parameter list will not be visible outside of this definition or declaration
    5 | int do_stuff__extern(struct struct_test s) { return do_stuff(s); }
      |                             ^~~~~~~~~~~
wrapper.c:5:41: error: parameter 1 (‘s’) has incomplete type
    5 | int do_stuff__extern(struct struct_test s) { return do_stuff(s); }
      |                      ~~~~~~~~~~~~~~~~~~~^
Expected Results

Enabling --c-naming unfortunately has a bad interaction with --wrap-static-fns. The used names in the generated wrapper C file include the prefix which then fails to match with the definitions from the original header. The correct behavior would be to use the original names in the generated wrapper source and only apply the C-naming prefixes to the Rust bindings.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.