summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDr. Chat <arkolbed@gmail.com>2021-12-30 11:28:06 -0600
committerEmilio Cobos Álvarez <emilio@crisal.io>2022-01-29 11:29:00 +0100
commit0587ff95a9a411c7392ff2aa1775f69ac36caff5 (patch)
tree3c18a3a6adb3d7bbd3cb5af26e746a82bce72369
parentf578b0b4505a46bbf7724eeaa48ea93f1a2aacea (diff)
On second thought, don't generate virtual destructors
-rw-r--r--src/codegen/mod.rs20
-rw-r--r--tests/expectations/tests/issue-1197-pure-virtual-stuff.rs5
-rw-r--r--tests/expectations/tests/packed-vtable.rs4
-rw-r--r--tests/expectations/tests/virtual_dtor.rs4
4 files changed, 13 insertions, 20 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 7a46f885..b7cee7ec 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1041,19 +1041,19 @@ impl<'a> CodeGenerator for Vtable<'a> {
assert_eq!(item.id(), self.item_id);
debug_assert!(item.is_enabled_for_codegen(ctx));
let name = ctx.rust_ident(&self.canonical_name(ctx));
- let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx));
- // For now, we will only generate vtables for classes that do not inherit from others.
- if self.comp_info.base_members().is_empty() {
- // Map the destructor into a Method, and chain it into the below iteration.
- let dtor = self
- .comp_info
- .destructor()
- .map(|(kind, id)| Method::new(kind, id, false));
+ // 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() &&
+ self.comp_info.destructor().is_none()
+ {
+ let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx));
- let methods = dtor
+ let methods = self
+ .comp_info
+ .methods()
.iter()
- .chain(self.comp_info.methods().iter())
.filter_map(|m| {
if !m.is_virtual() {
return None;
diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs
index 0b91eb24..fd023363 100644
--- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs
+++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs
@@ -6,10 +6,7 @@
)]
#[repr(C)]
-pub struct Foo__bindgen_vtable {
- pub Foo_Foo_destructor: fn(this: &mut Foo),
- pub Foo_Bar: fn(this: &mut Foo),
-}
+pub struct Foo__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug)]
pub struct Foo {
diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs
index 33989101..0069eada 100644
--- a/tests/expectations/tests/packed-vtable.rs
+++ b/tests/expectations/tests/packed-vtable.rs
@@ -7,9 +7,7 @@
#![cfg(feature = "nightly")]
#[repr(C)]
-pub struct PackedVtable__bindgen_vtable {
- pub PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable),
-}
+pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void);
#[repr(C, packed)]
#[derive(Debug)]
pub struct PackedVtable {
diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs
index 5d8834fa..c3c66e91 100644
--- a/tests/expectations/tests/virtual_dtor.rs
+++ b/tests/expectations/tests/virtual_dtor.rs
@@ -6,9 +6,7 @@
)]
#[repr(C)]
-pub struct nsSlots__bindgen_vtable {
- pub nsSlots_nsSlots_destructor: fn(this: &mut nsSlots),
-}
+pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug)]
pub struct nsSlots {