Skip to content

Commit b4e3be9

Browse files
author
bors-servo
authored
Auto merge of #597 - servo:void-vtable, r=fitzgen,emilio
Make vtables non-zero-size to fix a rustc warning. ``` warning: found non-foreign-function-safe member in struct marked #[repr(C)]: found zero-size struct in foreign module, consider adding a member to this struct ``` Emilio said on IRC: > the empty vtable means that we don't care of figuring out the proper vtable layout, so we create an empty struct Sounds like all that matters is to have a pointer, we don’t look at the data behind it. Using `c_void` seems appropriate, then.
2 parents cc6f3b2 + f67967a commit b4e3be9

8 files changed

+12
-30
lines changed

src/codegen/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,17 +706,15 @@ impl<'a> CodeGenerator for Vtable<'a> {
706706
assert_eq!(item.id(), self.item_id);
707707
// For now, generate an empty struct, later we should generate function
708708
// pointers and whatnot.
709-
let mut attributes = vec![attributes::repr("C")];
710-
711-
if ctx.options().derive_default {
712-
attributes.push(attributes::derives(&["Default"]))
713-
}
709+
let attributes = vec![attributes::repr("C")];
714710

715711
let vtable = aster::AstBuilder::new()
716712
.item()
717713
.pub_()
718714
.with_attrs(attributes)
719-
.struct_(self.canonical_name(ctx))
715+
.tuple_struct(self.canonical_name(ctx))
716+
.field()
717+
.build_ty(helpers::ast_ty::raw_type(ctx, "c_void"))
720718
.build();
721719
result.push(vtable);
722720
}

tests/expectations/tests/enum_and_vtable_mangling.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
1010
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1111
pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, }
1212
#[repr(C)]
13-
#[derive(Default)]
14-
pub struct C__bindgen_vtable {
15-
}
13+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
1614
#[repr(C)]
1715
#[derive(Debug, Copy)]
1816
pub struct C {

tests/expectations/tests/nested_vtable.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66

77
#[repr(C)]
8-
#[derive(Default)]
9-
pub struct nsISupports__bindgen_vtable {
10-
}
8+
pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void);
119
#[repr(C)]
1210
#[derive(Debug, Copy)]
1311
pub struct nsISupports {

tests/expectations/tests/ref_argument_array.rs

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

77
pub const NSID_LENGTH: ::std::os::raw::c_uint = 10;
88
#[repr(C)]
9-
#[derive(Default)]
10-
pub struct nsID__bindgen_vtable {
11-
}
9+
pub struct nsID__bindgen_vtable(::std::os::raw::c_void);
1210
#[repr(C)]
1311
#[derive(Debug, Copy)]
1412
pub struct nsID {

tests/expectations/tests/virtual_dtor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66

77
#[repr(C)]
8-
#[derive(Default)]
9-
pub struct nsSlots__bindgen_vtable {
10-
}
8+
pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void);
119
#[repr(C)]
1210
#[derive(Debug)]
1311
pub struct nsSlots {

tests/expectations/tests/virtual_inheritance.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ impl Clone for A {
2525
fn clone(&self) -> Self { *self }
2626
}
2727
#[repr(C)]
28-
#[derive(Default)]
29-
pub struct B__bindgen_vtable {
30-
}
28+
pub struct B__bindgen_vtable(::std::os::raw::c_void);
3129
#[repr(C)]
3230
#[derive(Debug, Copy)]
3331
pub struct B {
@@ -53,9 +51,7 @@ impl Default for B {
5351
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
5452
}
5553
#[repr(C)]
56-
#[derive(Default)]
57-
pub struct C__bindgen_vtable {
58-
}
54+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
5955
#[repr(C)]
6056
#[derive(Debug, Copy)]
6157
pub struct C {

tests/expectations/tests/virtual_overloaded.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66

77
#[repr(C)]
8-
#[derive(Default)]
9-
pub struct C__bindgen_vtable {
10-
}
8+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
119
#[repr(C)]
1210
#[derive(Debug, Copy)]
1311
pub struct C {

tests/expectations/tests/vtable_recursive_sig.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ impl Default for Derived {
2323
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
2424
}
2525
#[repr(C)]
26-
#[derive(Default)]
27-
pub struct Base__bindgen_vtable {
28-
}
26+
pub struct Base__bindgen_vtable(::std::os::raw::c_void);
2927
#[repr(C)]
3028
#[derive(Debug, Copy)]
3129
pub struct Base {

0 commit comments

Comments
 (0)