Skip to content

Commit

Permalink
Put vtable generation behind a flag for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Feb 18, 2022
1 parent e180d14 commit 68d2b0e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,8 @@ impl<'a> CodeGenerator for Vtable<'a> {
// For now, we will only generate vtables for classes that:
// - do not inherit from others (compilers merge VTable from primary parent class).
// - do not contain a virtual destructor (requires ordering; platforms generate different vtables).
if self.comp_info.base_members().is_empty() &&
if ctx.options().vtable_generation &&
self.comp_info.base_members().is_empty() &&
self.comp_info.destructor().is_none()
{
let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx));
Expand Down Expand Up @@ -1793,7 +1794,7 @@ impl CodeGenerator for CompInfo {

if !is_opaque {
if item.has_vtable_ptr(ctx) {
let vtable = Vtable::new(item.id(), &self);
let vtable = Vtable::new(item.id(), self);
vtable.codegen(ctx, result, item);

let vtable_type = vtable
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ impl Builder {
output_vector.push("--explicit-padding".into());
}

if self.options.vtable_generation {
output_vector.push("--vtable-generation".into());
}

// Add clang arguments

output_vector.push("--".into());
Expand Down Expand Up @@ -1450,6 +1454,14 @@ impl Builder {
self
}

/// If true, enables experimental support to generate vtable functions.
///
/// Should mostly work, though some edge cases are likely to be broken.
pub fn vtable_generation(mut self, doit: bool) -> Self {
self.options.vtable_generation = doit;
self
}

/// Generate the Rust bindings using the options built up thus far.
pub fn generate(mut self) -> Result<Bindings, BindgenError> {
// Add any extra arguments from the environment to the clang command line.
Expand Down Expand Up @@ -1981,6 +1993,9 @@ struct BindgenOptions {

/// Always output explicit padding fields
force_explicit_padding: bool,

/// Emit vtable functions.
vtable_generation: bool,
}

/// TODO(emilio): This is sort of a lie (see the error message that results from
Expand Down Expand Up @@ -2128,6 +2143,7 @@ impl Default for BindgenOptions {
translate_enum_integer_types: false,
c_naming: false,
force_explicit_padding: false,
vtable_generation: false,
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ where
Arg::new("explicit-padding")
.long("explicit-padding")
.help("Always output explicit padding fields."),
Arg::new("vtable-generation")
.long("vtable-generation")
.help("Enables generation of vtable functions."),
]) // .args()
.get_matches_from(args);

Expand Down Expand Up @@ -1008,6 +1011,10 @@ where
builder = builder.explicit_padding(true);
}

if matches.is_present("vtable-generation") {
builder = builder.vtable_generation(true);
}

let verbose = matches.is_present("verbose");

Ok((builder, output, verbose))
Expand Down
1 change: 1 addition & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ fn create_bindgen_builder(header: &Path) -> Result<BuilderState, Error> {
"--no-rustfmt-bindings",
"--with-derive-default",
"--disable-header-comment",
"--vtable-generation",
header_str,
"--raw-line",
"",
Expand Down

0 comments on commit 68d2b0e

Please sign in to comment.