Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide option to get real virtual fn receiver. #3138

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions bindgen-tests/tests/expectations/tests/specific_receiver.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions bindgen-tests/tests/headers/specific_receiver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: --use-specific-virtual-function-receiver --generate-inline-functions -- -x c++ -std=c++14

class Fish {
public:
virtual void swim() {
}
};
5 changes: 4 additions & 1 deletion bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ impl FunctionSig {
let is_const = is_method && cursor.method_is_const();
let is_virtual = is_method && cursor.method_is_virtual();
let is_static = is_method && cursor.method_is_static();
if !is_static && !is_virtual {
if !is_static &&
(!is_virtual ||
ctx.options().use_specific_virtual_function_receiver)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be worth making the default behavior fwiw. This goes back to cfdf15f. But yeah making it opt-in makes sense to me.

let parent = cursor.semantic_parent();
let class = Item::parse(parent, None, ctx)
.expect("Expected to parse the class");
Expand Down
5 changes: 5 additions & 0 deletions bindgen/options/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ struct BindgenCommand {
/// Always output explicit padding fields.
#[arg(long)]
explicit_padding: bool,
/// Always be specific about the 'receiver' of a virtual function.
#[arg(long)]
use_specific_virtual_function_receiver: bool,
/// Use distinct char16_t
#[arg(long)]
use_distinct_char16_t: bool,
Expand Down Expand Up @@ -632,6 +635,7 @@ where
translate_enum_integer_types,
c_naming,
explicit_padding,
use_specific_virtual_function_receiver,
use_distinct_char16_t,
vtable_generation,
sort_semantically,
Expand Down Expand Up @@ -930,6 +934,7 @@ where
translate_enum_integer_types,
c_naming,
explicit_padding,
use_specific_virtual_function_receiver,
use_distinct_char16_t,
vtable_generation,
sort_semantically,
Expand Down
15 changes: 15 additions & 0 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ macro_rules! options {
}

options! {
/// Whether to specify the type of a virtual function receiver
use_specific_virtual_function_receiver: bool {
methods: {
/// Normally, virtual functions have void* as their 'this' type.
/// If this flag is enabled, override that behavior to indicate a
/// pointer of the specific type.
/// Disabled by default.
pub fn use_specific_virtual_function_receiver(mut self, doit: bool) -> Builder {
self.options.use_specific_virtual_function_receiver = doit;
self
}
},
as_args: "--use-specific-virtual-function-receiver",
},

/// Whether we should distinguish between C++'s 'char16_t' and 'u16'.
/// The C++ type `char16_t` is its own special type; it's not a typedef
/// of some other integer (this differs from C).
Expand Down
Loading