Skip to content

Commit 0587ff9

Browse files
DrChatemilio
authored andcommitted
On second thought, don't generate virtual destructors
1 parent f578b0b commit 0587ff9

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

src/codegen/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,19 +1041,19 @@ impl<'a> CodeGenerator for Vtable<'a> {
10411041
assert_eq!(item.id(), self.item_id);
10421042
debug_assert!(item.is_enabled_for_codegen(ctx));
10431043
let name = ctx.rust_ident(&self.canonical_name(ctx));
1044-
let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx));
10451044

1046-
// For now, we will only generate vtables for classes that do not inherit from others.
1047-
if self.comp_info.base_members().is_empty() {
1048-
// Map the destructor into a Method, and chain it into the below iteration.
1049-
let dtor = self
1050-
.comp_info
1051-
.destructor()
1052-
.map(|(kind, id)| Method::new(kind, id, false));
1045+
// For now, we will only generate vtables for classes that:
1046+
// - do not inherit from others (compilers merge VTable from primary parent class).
1047+
// - do not contain a virtual destructor (requires ordering; platforms generate different vtables).
1048+
if self.comp_info.base_members().is_empty() &&
1049+
self.comp_info.destructor().is_none()
1050+
{
1051+
let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx));
10531052

1054-
let methods = dtor
1053+
let methods = self
1054+
.comp_info
1055+
.methods()
10551056
.iter()
1056-
.chain(self.comp_info.methods().iter())
10571057
.filter_map(|m| {
10581058
if !m.is_virtual() {
10591059
return None;

tests/expectations/tests/issue-1197-pure-virtual-stuff.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
)]
77

88
#[repr(C)]
9-
pub struct Foo__bindgen_vtable {
10-
pub Foo_Foo_destructor: fn(this: &mut Foo),
11-
pub Foo_Bar: fn(this: &mut Foo),
12-
}
9+
pub struct Foo__bindgen_vtable(::std::os::raw::c_void);
1310
#[repr(C)]
1411
#[derive(Debug)]
1512
pub struct Foo {

tests/expectations/tests/packed-vtable.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#![cfg(feature = "nightly")]
88

99
#[repr(C)]
10-
pub struct PackedVtable__bindgen_vtable {
11-
pub PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable),
12-
}
10+
pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void);
1311
#[repr(C, packed)]
1412
#[derive(Debug)]
1513
pub struct PackedVtable {

tests/expectations/tests/virtual_dtor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
)]
77

88
#[repr(C)]
9-
pub struct nsSlots__bindgen_vtable {
10-
pub nsSlots_nsSlots_destructor: fn(this: &mut nsSlots),
11-
}
9+
pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void);
1210
#[repr(C)]
1311
#[derive(Debug)]
1412
pub struct nsSlots {

0 commit comments

Comments
 (0)