diff options
-rw-r--r-- | src/codegen/mod.rs | 36 | ||||
-rw-r--r-- | tests/expectations/tests/enum_and_vtable_mangling.rs | 4 | ||||
-rw-r--r-- | tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs | 2 | ||||
-rw-r--r-- | tests/expectations/tests/issue-1197-pure-virtual-stuff.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/issue-691-template-parameter-virtual.rs | 2 | ||||
-rw-r--r-- | tests/expectations/tests/nested_vtable.rs | 4 | ||||
-rw-r--r-- | tests/expectations/tests/packed-vtable.rs | 4 | ||||
-rw-r--r-- | tests/expectations/tests/ref_argument_array.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/virtual_dtor.rs | 4 | ||||
-rw-r--r-- | tests/expectations/tests/virtual_interface.rs | 7 | ||||
-rw-r--r-- | tests/expectations/tests/virtual_overloaded.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/vtable_recursive_sig.rs | 4 |
12 files changed, 49 insertions, 33 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index c7801030..2b10b3de 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -21,8 +21,8 @@ use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::FieldAccessorKind; use crate::ir::comment; use crate::ir::comp::{ - Base, Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, - FieldMethods, Method, MethodKind, + Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, FieldMethods, + Method, MethodKind, }; use crate::ir::context::{BindgenContext, ItemId}; use crate::ir::derive::{ @@ -1017,23 +1017,14 @@ impl CodeGenerator for Type { struct Vtable<'a> { item_id: ItemId, + /// A reference to the originating compound object. #[allow(dead_code)] - methods: &'a [Method], - #[allow(dead_code)] - base_classes: &'a [Base], + comp_info: &'a CompInfo, } impl<'a> Vtable<'a> { - fn new( - item_id: ItemId, - methods: &'a [Method], - base_classes: &'a [Base], - ) -> Self { - Vtable { - item_id, - methods, - base_classes, - } + fn new(item_id: ItemId, comp_info: &'a CompInfo) -> Self { + Vtable { item_id, comp_info } } } @@ -1053,10 +1044,16 @@ impl<'a> CodeGenerator for Vtable<'a> { 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.base_classes.is_empty() { - let methods = self - .methods + 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)); + + let methods = dtor .iter() + .chain(self.comp_info.methods().iter()) .filter_map(|m| { if !m.is_virtual() { return None; @@ -1796,8 +1793,7 @@ impl CodeGenerator for CompInfo { if !is_opaque { if item.has_vtable_ptr(ctx) { - let vtable = - Vtable::new(item.id(), self.methods(), self.base_members()); + let vtable = Vtable::new(item.id(), &self); vtable.codegen(ctx, result, item); let vtable_type = vtable diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 9e9c6bcb..c0414c37 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -14,7 +14,9 @@ pub enum _bindgen_ty_1 { whatever_else = 1, } #[repr(C)] -pub struct C__bindgen_vtable(::std::os::raw::c_void); +pub struct C__bindgen_vtable { + C_match: fn(this: &mut C), +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index f292125d..0876878e 100644 --- a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -6,7 +6,7 @@ )] #[repr(C)] -pub struct BaseWithVtable__bindgen_vtable(::std::os::raw::c_void); +pub struct BaseWithVtable__bindgen_vtable {} /// This should have an explicit vtable. #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index fd023363..80606c2a 100644 --- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -6,7 +6,10 @@ )] #[repr(C)] -pub struct Foo__bindgen_vtable(::std::os::raw::c_void); +pub struct Foo__bindgen_vtable { + Foo_Foo_destructor: fn(this: &mut Foo), + Foo_Bar: fn(this: &mut Foo), +} #[repr(C)] #[derive(Debug)] pub struct Foo { diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 4747b955..e71b2aae 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -6,7 +6,7 @@ )] #[repr(C)] -pub struct VirtualMethods__bindgen_vtable(::std::os::raw::c_void); +pub struct VirtualMethods__bindgen_vtable {} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct VirtualMethods { diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 02187776..2b0f2599 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -6,7 +6,9 @@ )] #[repr(C)] -pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void); +pub struct nsISupports__bindgen_vtable { + nsISupports_QueryInterface: fn(this: &mut nsISupports) -> *mut nsISupports, +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsISupports { diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 0069eada..05fea619 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -7,7 +7,9 @@ #![cfg(feature = "nightly")] #[repr(C)] -pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); +pub struct PackedVtable__bindgen_vtable { + PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable), +} #[repr(C, packed)] #[derive(Debug)] pub struct PackedVtable { diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 799dd815..04938d15 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -7,7 +7,10 @@ pub const NSID_LENGTH: u32 = 10; #[repr(C)] -pub struct nsID__bindgen_vtable(::std::os::raw::c_void); +pub struct nsID__bindgen_vtable { + nsID_ToProvidedString: + fn(this: &mut nsID, aDest: *mut [::std::os::raw::c_char; 10usize]), +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsID { diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index c3c66e91..5af64bfe 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -6,7 +6,9 @@ )] #[repr(C)] -pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); +pub struct nsSlots__bindgen_vtable { + nsSlots_nsSlots_destructor: fn(this: &mut nsSlots), +} #[repr(C)] #[derive(Debug)] pub struct nsSlots { diff --git a/tests/expectations/tests/virtual_interface.rs b/tests/expectations/tests/virtual_interface.rs index 5d4f1bbc..ecd547fb 100644 --- a/tests/expectations/tests/virtual_interface.rs +++ b/tests/expectations/tests/virtual_interface.rs @@ -7,8 +7,9 @@ #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { - PureVirtualIFace_Foo: fn(&mut self), - PureVirtualIFace_Bar: fn(&mut self, arg1: ::std::os::raw::c_uint), + PureVirtualIFace_Foo: fn(this: &mut PureVirtualIFace), + PureVirtualIFace_Bar: + fn(this: &mut PureVirtualIFace, arg1: ::std::os::raw::c_uint), } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -39,7 +40,7 @@ impl Default for PureVirtualIFace { } #[repr(C)] pub struct AnotherInterface__bindgen_vtable { - AnotherInterface_Baz: fn(&mut self), + AnotherInterface_Baz: fn(this: &mut AnotherInterface), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 4556b1b6..771e08c0 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -6,7 +6,10 @@ )] #[repr(C)] -pub struct C__bindgen_vtable(::std::os::raw::c_void); +pub struct C__bindgen_vtable { + C_do_thing: fn(this: &mut C, arg1: ::std::os::raw::c_char), + C_do_thing1: fn(this: &mut C, arg1: ::std::os::raw::c_int), +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index ca77bc8c..c10f2f0f 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -6,7 +6,9 @@ )] #[repr(C)] -pub struct Base__bindgen_vtable(::std::os::raw::c_void); +pub struct Base__bindgen_vtable { + Base_AsDerived: fn(this: &mut Base) -> *mut Derived, +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Base { |