rust-lang / rust-lang/rust-bindgen

Interaction between wrapped statics and redefined function

Open
#2,420 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Input C/C++ Header
static inline int foo(int a, int b) {
    return a + b;
}

#define foo(a) foo(a, a + 5)
Bindgen Invocation
$ bindgen --experimental --wrap-static-fns input.h
Actual Results
extern "C" {
    #[link_name = "\u{1}foo__extern"]
    pub fn foo(a: ::std::os::raw::c_int, b: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
}

and

int foo__extern(int a, int b) asm("foo__extern");
int foo__extern(int a, int b) { return foo(a, b); }

and compiling the C wrapper:

$ cc -include input.h /tmp/bindgen/extern.c
/tmp/bindgen/extern.c: In function 'foo__extern':
/tmp/bindgen/extern.c:2:48: error: macro "foo" passed 2 arguments, but takes just 1
    2 | int foo__extern(int a, int b) { return foo(a, b); }
      |                                                ^
In file included from <command-line>:
./input.h:5: note: macro "foo" defined here
    5 | #define foo(a) foo(a, a + 5)
Expected Results

I don't really know. Is this something that should work? If yes, how ?

cc @pvdrz

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

Reproduce the issue with input.h and the bindgen --experimental --wrap-static-fns invocation, then inspect the generated Rust declaration and /tmp/bindgen/extern.c wrapper. Determine whether wrapped static functions can coexist with the redefined foo macro, and establish expected behavior before changing anything. Done means the wrapper compiles or the limitation is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.