rust-lang / rust-lang/rust-bindgen
Incorrect wrapper generated by `--wrap-static-fns --c-naming`
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.