]> Repositorios git - scryer-prolog.git/commitdiff
some fixes in response to miri
authorMark Thom <[email protected]>
Thu, 13 Mar 2025 19:33:37 +0000 (12:33 -0700)
committerMark Thom <[email protected]>
Wed, 23 Apr 2025 06:32:32 +0000 (23:32 -0700)
src/ffi.rs
src/lib/builtins.pl
src/machine/heap.rs
src/machine/machine_state_impl.rs
src/machine/stack.rs
src/types.rs

index a3e933800adda8fb89fda716aa9a68db1cefa4d5..2895009b013c4722176fa175b4d409412798942d 100644 (file)
@@ -89,27 +89,25 @@ impl ForeignFunctionTable {
     }
 
     fn map_type_ffi(&mut self, source: &Atom) -> *mut ffi_type {
-        unsafe {
-            match source {
-                atom!("sint64") => addr_of_mut!(types::sint64),
-                atom!("sint32") => addr_of_mut!(types::sint32),
-                atom!("sint16") => addr_of_mut!(types::sint16),
-                atom!("sint8") => addr_of_mut!(types::sint8),
-                atom!("uint64") => addr_of_mut!(types::uint64),
-                atom!("uint32") => addr_of_mut!(types::uint32),
-                atom!("uint16") => addr_of_mut!(types::uint16),
-                atom!("uint8") => addr_of_mut!(types::uint8),
-                atom!("bool") => addr_of_mut!(types::sint8),
-                atom!("void") => addr_of_mut!(types::void),
-                atom!("cstr") => addr_of_mut!(types::pointer),
-                atom!("ptr") => addr_of_mut!(types::pointer),
-                atom!("f32") => addr_of_mut!(types::float),
-                atom!("f64") => addr_of_mut!(types::double),
-                struct_name => match self.structs.get_mut(&*struct_name.as_str()) {
-                    Some(ref mut struct_type) => &mut struct_type.ffi_type,
-                    None => unreachable!(),
-                },
-            }
+        match source {
+            atom!("sint64") => addr_of_mut!(types::sint64),
+            atom!("sint32") => addr_of_mut!(types::sint32),
+            atom!("sint16") => addr_of_mut!(types::sint16),
+            atom!("sint8") => addr_of_mut!(types::sint8),
+            atom!("uint64") => addr_of_mut!(types::uint64),
+            atom!("uint32") => addr_of_mut!(types::uint32),
+            atom!("uint16") => addr_of_mut!(types::uint16),
+            atom!("uint8") => addr_of_mut!(types::uint8),
+            atom!("bool") => addr_of_mut!(types::sint8),
+            atom!("void") => addr_of_mut!(types::void),
+            atom!("cstr") => addr_of_mut!(types::pointer),
+            atom!("ptr") => addr_of_mut!(types::pointer),
+            atom!("f32") => addr_of_mut!(types::float),
+            atom!("f64") => addr_of_mut!(types::double),
+            struct_name => match self.structs.get_mut(&*struct_name.as_str()) {
+                Some(ref mut struct_type) => &mut struct_type.ffi_type,
+                None => unreachable!(),
+            },
         }
     }
 
index 4e8cb44e5dc1f15f73b351535d95967b9be2df9e..2b9742284df818069b7dbc0966e4647aa4d4d87a 100644 (file)
@@ -568,7 +568,6 @@ parse_options_list(Options, Selector, DefaultPairs, OptionValues, Stub) :-
                                                 % maplist isn't
                                                 % declared as a
                                                 % meta-predicate yet
-       '$debug_hook',
        catch(lists:maplist(Selector, Options, OptionPairs0),
              error(E, _),
              builtins:throw(error(E, Stub))) ->
index b753809dfa9c461a981bd32d7a0871327bbbe3be..d628391c661cc0971937914449a95fd0ad744607 100644 (file)
@@ -1281,3 +1281,17 @@ pub(crate) fn to_local_code_ptr(heap: &Heap, addr: HeapCellValue) -> Option<usiz
         }
     )
 }
+
+#[cfg(test)]
+mod test {
+    use super::*;
+
+    #[test]
+    fn heap_manipulation() {
+        let mut heap = Heap::new();
+
+        for idx in 0 .. 10 {
+            heap.push_cell(heap_loc_as_cell!(idx)).unwrap();
+        }
+    }
+}
index a7dc5d9e8e767ec5bfa9909890551f9a5ae85fa9..ef1d32dc275cf78636c766dced21b7699bff8d77 100644 (file)
@@ -267,16 +267,6 @@ impl MachineState {
         unifier.unify_atom(atom, value);
     }
 
-    pub fn unify_list(&mut self, l1: usize, value: HeapCellValue) {
-        let mut unifier = DefaultUnifier::from(self);
-        unifier.unify_list(l1, value);
-    }
-
-    pub fn unify_partial_string(&mut self, pstr_loc: usize, value: HeapCellValue) {
-        let mut unifier = DefaultUnifier::from(self);
-        unifier.unify_partial_string(pstr_loc, value);
-    }
-
     pub fn unify_char(&mut self, c: char, value: HeapCellValue) {
         let mut unifier = DefaultUnifier::from(self);
         unifier.unify_char(c, value);
index bf330813dfc34c3312db373d59df18b5dc740f50..4d8b970adfd376a597f0fb26c9dd5692d2fb4784 100644 (file)
@@ -228,7 +228,7 @@ impl Stack {
 
             for idx in 0..num_cells {
                 ptr::write(
-                    (new_ptr as usize + offset) as *mut HeapCellValue,
+                    new_ptr.byte_add(offset) as *mut HeapCellValue,
                     stack_loc_as_cell!(OrFrame, b, idx),
                 );
 
index 5eee7fcc9d4546e89ff0992114090b6e1ab01f2d..125e3648f1c269ec4ebfd855042f069218623655 100644 (file)
@@ -97,8 +97,9 @@ impl ConsPtr {
 
     #[inline(always)]
     pub fn as_ptr(self) -> *mut u8 {
-        let addr: u64 = self.ptr();
-        addr as usize as *mut _
+        unsafe {
+            mem::transmute::<_, *mut u8>(self.ptr())
+        }
     }
 
     #[inline(always)]
@@ -675,22 +676,23 @@ impl UntypedArenaPtr {
     }
 
     #[inline]
-    pub fn get_ptr(self) -> *const u8 {
-        let addr: u64 = self.ptr();
-        addr as usize as *const u8
+    pub fn get_ptr(self) -> *const ArenaHeader {
+        unsafe {
+            mem::transmute::<_, *const ArenaHeader>(self.ptr())
+        }
     }
 
     #[inline]
     pub fn get_tag(self) -> ArenaHeaderTag {
         unsafe {
-            let header = *(self.get_ptr() as *const ArenaHeader);
+            let header = *self.get_ptr();
             header.get_tag()
         }
     }
 
     #[inline]
     pub fn payload_offset(self) -> *const u8 {
-        unsafe { self.get_ptr().add(mem::size_of::<ArenaHeader>()) }
+        unsafe { self.get_ptr().byte_add(mem::size_of::<ArenaHeader>()) as *const _ }
     }
 
     /// # Safety