Skip to content

Commit 399af44

Browse files
emilioAatif Syed
authored and
Aatif Syed
committed
Put vtable generation behind a flag for now.
1 parent 1f0767e commit 399af44

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/codegen/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,8 @@ impl<'a> CodeGenerator for Vtable<'a> {
10451045
// For now, we will only generate vtables for classes that:
10461046
// - do not inherit from others (compilers merge VTable from primary parent class).
10471047
// - do not contain a virtual destructor (requires ordering; platforms generate different vtables).
1048-
if self.comp_info.base_members().is_empty() &&
1048+
if ctx.options().vtable_generation &&
1049+
self.comp_info.base_members().is_empty() &&
10491050
self.comp_info.destructor().is_none()
10501051
{
10511052
let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx));
@@ -1793,7 +1794,7 @@ impl CodeGenerator for CompInfo {
17931794

17941795
if !is_opaque {
17951796
if item.has_vtable_ptr(ctx) {
1796-
let vtable = Vtable::new(item.id(), &self);
1797+
let vtable = Vtable::new(item.id(), self);
17971798
vtable.codegen(ctx, result, item);
17981799

17991800
let vtable_type = vtable

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ impl Builder {
569569
output_vector.push("--explicit-padding".into());
570570
}
571571

572+
if self.options.vtable_generation {
573+
output_vector.push("--vtable-generation".into());
574+
}
575+
572576
// Add clang arguments
573577

574578
output_vector.push("--".into());
@@ -1450,6 +1454,14 @@ impl Builder {
14501454
self
14511455
}
14521456

1457+
/// If true, enables experimental support to generate vtable functions.
1458+
///
1459+
/// Should mostly work, though some edge cases are likely to be broken.
1460+
pub fn vtable_generation(mut self, doit: bool) -> Self {
1461+
self.options.vtable_generation = doit;
1462+
self
1463+
}
1464+
14531465
/// Generate the Rust bindings using the options built up thus far.
14541466
pub fn generate(mut self) -> Result<Bindings, BindgenError> {
14551467
// Add any extra arguments from the environment to the clang command line.
@@ -1981,6 +1993,9 @@ struct BindgenOptions {
19811993

19821994
/// Always output explicit padding fields
19831995
force_explicit_padding: bool,
1996+
1997+
/// Emit vtable functions.
1998+
vtable_generation: bool,
19841999
}
19852000

19862001
/// TODO(emilio): This is sort of a lie (see the error message that results from
@@ -2128,6 +2143,7 @@ impl Default for BindgenOptions {
21282143
translate_enum_integer_types: false,
21292144
c_naming: false,
21302145
force_explicit_padding: false,
2146+
vtable_generation: false,
21312147
}
21322148
}
21332149
}

src/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ where
542542
Arg::new("explicit-padding")
543543
.long("explicit-padding")
544544
.help("Always output explicit padding fields."),
545+
Arg::new("vtable-generation")
546+
.long("vtable-generation")
547+
.help("Enables generation of vtable functions."),
545548
]) // .args()
546549
.get_matches_from(args);
547550

@@ -1008,6 +1011,10 @@ where
10081011
builder = builder.explicit_padding(true);
10091012
}
10101013

1014+
if matches.is_present("vtable-generation") {
1015+
builder = builder.vtable_generation(true);
1016+
}
1017+
10111018
let verbose = matches.is_present("verbose");
10121019

10131020
Ok((builder, output, verbose))

tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ fn create_bindgen_builder(header: &Path) -> Result<BuilderState, Error> {
365365
"--no-rustfmt-bindings",
366366
"--with-derive-default",
367367
"--disable-header-comment",
368+
"--vtable-generation",
368369
header_str,
369370
"--raw-line",
370371
"",

0 commit comments

Comments
 (0)