]> Repositorios git - scryer-prolog.git/commitdiff
unify pointer width
authorBennet Bleßmann <[email protected]>
Fri, 5 Jul 2024 23:41:05 +0000 (01:41 +0200)
committerBennet Bleßmann <[email protected]>
Fri, 5 Jul 2024 23:49:25 +0000 (01:49 +0200)
src/macros.rs
src/types.rs

index 3523cbd4c106e2f6bf0194255fb7bc9da57881c0..54fcaa63d2bc110bfcef7593d19e8bf557cb6e63 100644 (file)
@@ -171,12 +171,13 @@ macro_rules! typed_arena_ptr_as_cell {
 }
 
 macro_rules! raw_ptr_as_cell {
-    ($ptr:expr) => {
+    ($ptr:expr) => {{
         // Cell is 64-bit, but raw ptr is 32-bit in 32-bit systems
         // TODO use <*{const,mut} _>::addr instead of as when the strict_provenance feature is stable rust-lang/rust#95228
         // we might need <*{const,mut} _>::expose_provenance for strict provenance, dependening on how we recreate a pointer later
-        HeapCellValue::from_raw_ptr_bytes(($ptr as usize).to_ne_bytes())
-    };
+        let ptr : *const _ = $ptr;
+        HeapCellValue::from_ptr_addr(ptr as usize)
+    }};
 }
 
 macro_rules! untyped_arena_ptr_as_cell {
index badf58bebd53e7e8b8fc6f0137b330d8042bf932..40209ebfe4262ab47734fe7c4a1c33f886fce0b4 100644 (file)
@@ -88,18 +88,10 @@ impl ConsPtr {
             .with_tag(tag)
     }
 
-    #[cfg(target_pointer_width = "32")]
     #[inline(always)]
     pub fn as_ptr(self) -> *mut u8 {
-        let bytes = self.into_bytes();
-        let raw_ptr_bytes = [bytes[1], bytes[2], bytes[3], bytes[4]];
-        unsafe { mem::transmute(raw_ptr_bytes) }
-    }
-
-    #[cfg(target_pointer_width = "64")]
-    #[inline(always)]
-    pub fn as_ptr(self) -> *mut u8 {
-        self.ptr() as *mut _
+        let addr: u64 = self.ptr();
+        addr as usize as *mut _
     }
 
     #[inline(always)]
@@ -534,37 +526,13 @@ impl HeapCellValue {
         }
     }
 
-    #[cfg(target_pointer_width = "32")]
-    #[inline]
-    pub fn from_raw_ptr_bytes(ptr_bytes: [u8; 4]) -> Self {
-        HeapCellValue::from_bytes([
-            ptr_bytes[0],
-            ptr_bytes[1],
-            ptr_bytes[2],
-            ptr_bytes[3],
-            0,
-            0,
-            0,
-            0,
-        ])
-    }
-    #[cfg(target_pointer_width = "64")]
-    #[inline]
-    pub fn from_raw_ptr_bytes(ptr_bytes: [u8; 8]) -> Self {
-        HeapCellValue::from_bytes(ptr_bytes)
-    }
-
     #[inline]
-    #[cfg(target_pointer_width = "32")]
-    pub fn to_raw_ptr_bytes(self) -> [u8; 4] {
-        let bytes = self.into_bytes();
-        [bytes[0], bytes[1], bytes[2], bytes[3]]
+    pub fn from_ptr_addr(ptr_bytes: usize) -> Self {
+        HeapCellValue::from_bytes((ptr_bytes as u64).to_ne_bytes())
     }
 
-    #[inline]
-    #[cfg(target_pointer_width = "64")]
-    pub fn to_raw_ptr_bytes(self) -> [u8; 8] {
-        self.into_bytes()
+    pub fn to_ptr_addr(self) -> usize {
+        u64::from_ne_bytes(self.into_bytes()) as usize
     }
 
     #[inline]
@@ -716,18 +684,10 @@ impl UntypedArenaPtr {
         self.set_m(m);
     }
 
-    #[cfg(target_pointer_width = "32")]
-    #[inline]
-    pub fn get_ptr(self) -> *const u8 {
-        let bytes = self.into_bytes();
-        let raw_ptr_bytes = [bytes[0], bytes[1], bytes[2], bytes[3]];
-        unsafe { mem::transmute(raw_ptr_bytes) }
-    }
-
-    #[cfg(target_pointer_width = "64")]
     #[inline]
     pub fn get_ptr(self) -> *const u8 {
-        self.ptr() as *const u8
+        let addr: u64 = self.ptr();
+        addr as usize as *const u8
     }
 
     #[inline]