From 27e78dc3771675452b55181328739da1a7096783 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sun, 7 Jun 2026 09:49:30 +0200 Subject: [PATCH] Improved safety --- crates/codegen/src/class_decl.rs | 8 ++++---- mist-test/src/items/class_test.mist | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/codegen/src/class_decl.rs b/crates/codegen/src/class_decl.rs index c00bbb1..8fa1fe3 100644 --- a/crates/codegen/src/class_decl.rs +++ b/crates/codegen/src/class_decl.rs @@ -29,7 +29,7 @@ pub fn class_decl( )); 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 { cg.add_indented("pub _super: Box<"); @@ -250,7 +250,7 @@ impl GenRust cg.add_indentedln("let mut this = Box::new(unsafe { std::mem::MaybeUninit::::zeroed().assume_init() });"); cg.add_indentedln("let this_ptr = &mut *this as *mut Self as *mut std::ffi::c_void;"); 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 { @@ -280,7 +280,7 @@ impl GenRust if self.2 { 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.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() )); diff --git a/mist-test/src/items/class_test.mist b/mist-test/src/items/class_test.mist index 9d88134..b95f19d 100644 --- a/mist-test/src/items/class_test.mist +++ b/mist-test/src/items/class_test.mist @@ -8,6 +8,10 @@ pub class Animal { pub fn speak(*self) { println!("Unknown"); } + + pub fn test_speak(*self) { + self.speak(); + } } pub class Dog : Animal { @@ -25,5 +29,5 @@ pub class Dog : Animal { pub fn run_tests() { let dawg = Dog::new(); - dawg.speak(); + dawg.test_speak(); }