diff options
author | Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> | 2023-02-07 10:13:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 10:13:48 -0500 |
commit | 2be14a33451b0259bfed8e0fe517502e46fab7b6 (patch) | |
tree | c2775e75c393aab280598bb763db52d4859ccc3d /bindgen/ir/function.rs | |
parent | 62b48c56703eb5f734b9a333b1ae2be10ffa303e (diff) |
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>
Diffstat (limited to 'bindgen/ir/function.rs')
-rw-r--r-- | bindgen/ir/function.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 8e83d980..baa2c36c 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -664,7 +664,6 @@ impl ClangSubItemParser for Function { }; debug!("Function::parse({:?}, {:?})", cursor, cursor.cur_type()); - let visibility = cursor.visibility(); if visibility != CXVisibility_Default { return Err(ParseError::Continue); @@ -674,25 +673,36 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } + let linkage = cursor.linkage(); + let linkage = match linkage { + CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External, + CXLinkage_Internal => Linkage::Internal, + _ => return Err(ParseError::Continue), + }; + if cursor.is_inlined_function() || cursor .definition() .map_or(false, |x| x.is_inlined_function()) { - if !context.options().generate_inline_functions { + if !context.options().generate_inline_functions && + !context.options().wrap_static_fns + { return Err(ParseError::Continue); } + if cursor.is_deleted_function() { return Err(ParseError::Continue); } - } - let linkage = cursor.linkage(); - let linkage = match linkage { - CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External, - CXLinkage_Internal => Linkage::Internal, - _ => return Err(ParseError::Continue), - }; + // We cannot handle `inline` functions that are not `static`. + if context.options().wrap_static_fns && + cursor.is_inlined_function() && + matches!(linkage, Linkage::External) + { + return Err(ParseError::Continue); + } + } // Grab the signature using Item::from_ty. let sig = Item::from_ty(&cursor.cur_type(), cursor, None, context)?; @@ -727,7 +737,8 @@ impl ClangSubItemParser for Function { let comment = cursor.raw_comment(); let function = - Self::new(name, mangled_name, sig, comment, kind, linkage); + Self::new(name.clone(), mangled_name, sig, comment, kind, linkage); + Ok(ParseResult::New(function, Some(cursor))) } } |