-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate extern wrappers for inlined functions (#2335)
* Generate extern wrappers for inlined functions If bindgen finds an inlined function and the `--generate-extern-functions` options is enabled, then: - It will generate two new source and header files with external functions that wrap the inlined functions. - Rerun `Bindings::generate` using the new header file to include these wrappers in the generated bindings. The following additional options were added: - `--extern-function-suffix=<suffix>`: Adds <suffix> to the name of each external wrapper function (`__extern` is used by default). - `--extern-functions-file-name=<name>`: Uses <name> as the file name for the header and source files (`extern` is used by default). - `--extern-function-directory=<dir>`: Creates the source and header files inside <dir> (`/tmp/bindgen` is used by default). The C code serialization is experimental and only supports a very limited set of C functions. Fixes #1090. --------- Co-authored-by: Amanjeev Sethi <aj@amanjeev.com>
- Loading branch information
Showing
17 changed files
with
876 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Generated C, C++, Header files | ||
|
||
This directory contains files for features where extra files are generated | ||
as a part of the feature. For example, `--wrap-static-fns`. |
14 changes: 14 additions & 0 deletions
14
bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
int foo__extern(void) asm("foo__extern"); | ||
int foo__extern() { return foo(); } | ||
int bar__extern(void) asm("bar__extern"); | ||
int bar__extern() { return bar(); } | ||
int takes_ptr__extern(int *arg) asm("takes_ptr__extern"); | ||
int takes_ptr__extern(int *arg) { return takes_ptr(arg); } | ||
int takes_fn_ptr__extern(int (*f) (int)) asm("takes_fn_ptr__extern"); | ||
int takes_fn_ptr__extern(int (*f) (int)) { return takes_fn_ptr(f); } | ||
int takes_fn__extern(int (f) (int)) asm("takes_fn__extern"); | ||
int takes_fn__extern(int (f) (int)) { return takes_fn(f); } | ||
int takes_alias__extern(func f) asm("takes_alias__extern"); | ||
int takes_alias__extern(func f) { return takes_alias(f); } | ||
int takes_qualified__extern(const int *const *arg) asm("takes_qualified__extern"); | ||
int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// bindgen-flags: --experimental --wrap-static-fns | ||
|
||
static inline int foo() { | ||
return 11; | ||
} | ||
static int bar() { | ||
return 1; | ||
} | ||
inline int baz() { | ||
return 2; | ||
} | ||
|
||
static inline int takes_ptr(int* arg) { | ||
return *arg + 1; | ||
} | ||
|
||
static inline int takes_fn_ptr(int (*f)(int)) { | ||
return f(1); | ||
} | ||
|
||
static inline int takes_fn(int (f)(int)) { | ||
return f(2); | ||
} | ||
|
||
typedef int (func)(int); | ||
|
||
static inline int takes_alias(func f) { | ||
return f(3); | ||
} | ||
|
||
static inline int takes_qualified(const int *const *arg) { | ||
return **arg; | ||
} |
Oops, something went wrong.