Improved safety
This commit is contained in:
@@ -29,7 +29,7 @@ pub fn class_decl(
|
|||||||
));
|
));
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
cg.add_indentedln("pub _m_oop: (*const *const std::ffi::c_void, *mut std::ffi::c_void),");
|
cg.add_indentedln("pub _m_oop: (&'static [*const std::ffi::c_void; Self::__V_COUNT], *mut std::ffi::c_void),");
|
||||||
|
|
||||||
if let Some(inherits) = inherits {
|
if let Some(inherits) = inherits {
|
||||||
cg.add_indented("pub _super: Box<");
|
cg.add_indented("pub _super: Box<");
|
||||||
@@ -250,7 +250,7 @@ impl GenRust
|
|||||||
cg.add_indentedln("let mut this = Box::new(unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() });");
|
cg.add_indentedln("let mut this = Box::new(unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() });");
|
||||||
cg.add_indentedln("let this_ptr = &mut *this as *mut Self as *mut std::ffi::c_void;");
|
cg.add_indentedln("let this_ptr = &mut *this as *mut Self as *mut std::ffi::c_void;");
|
||||||
cg.add_indentedln(
|
cg.add_indentedln(
|
||||||
"this._m_oop = (&Self::__V_TABLE as *const *const std::ffi::c_void, this_ptr);",
|
"this._m_oop = (&Self::__V_TABLE, this_ptr);",
|
||||||
);
|
);
|
||||||
|
|
||||||
for field in self.0 {
|
for field in self.0 {
|
||||||
@@ -280,7 +280,7 @@ impl GenRust
|
|||||||
|
|
||||||
if self.2 {
|
if self.2 {
|
||||||
cg.add_indentedln(
|
cg.add_indentedln(
|
||||||
"this._super._m_oop.0 = &Self::__SUPER_V_TABLE as *const *const std::ffi::c_void;",
|
"this._super._m_oop.0 = &Self::__SUPER_V_TABLE;",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,7 +357,7 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
|||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
cg.add_indentedln(&format!(
|
cg.add_indentedln(&format!(
|
||||||
"let func_ptr = *self._m_oop.0.add(Self::__FN_{});",
|
"let func_ptr = self._m_oop.0[Self::__FN_{}];",
|
||||||
method.name.0.to_uppercase()
|
method.name.0.to_uppercase()
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ pub class Animal {
|
|||||||
pub fn speak(*self) {
|
pub fn speak(*self) {
|
||||||
println!("Unknown");
|
println!("Unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn test_speak(*self) {
|
||||||
|
self.speak();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub class Dog : Animal {
|
pub class Dog : Animal {
|
||||||
@@ -25,5 +29,5 @@ pub class Dog : Animal {
|
|||||||
pub fn run_tests() {
|
pub fn run_tests() {
|
||||||
let dawg = Dog::new();
|
let dawg = Dog::new();
|
||||||
|
|
||||||
dawg.speak();
|
dawg.test_speak();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user