]> Repositorios git - scryer-prolog.git/commitdiff
Add debug asserts to UntypedArenaPtr::build_with, ::get_tag and raw_ptr_as_cell!
authorEmilie Burgun <[email protected]>
Fri, 31 Jan 2025 14:12:54 +0000 (15:12 +0100)
committerEmilie Burgun <[email protected]>
Fri, 31 Jan 2025 14:15:52 +0000 (15:15 +0100)
These two functions are pretty unsafe, but having these assertions makes
it easier to catch UB in testing.

src/macros.rs
src/types.rs

index 30a863cac21439ac9ca57cd1890febcaf1c660dc..7778c89e6dc58add8fe3cd7badef50bda24df8f9 100644 (file)
@@ -175,6 +175,7 @@ macro_rules! raw_ptr_as_cell {
         // 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
         let ptr : *const _ = $ptr;
+        debug_assert!(!$ptr.is_null());
         HeapCellValue::from_ptr_addr(ptr as usize)
     }};
 }
index 49ff0a6e95dc053ce76547a7c9df743e6559935b..d68daac7c21fe2fb50ba75ab346207f0160d4dd7 100644 (file)
@@ -656,6 +656,7 @@ pub struct UntypedArenaPtr {
 impl UntypedArenaPtr {
     #[inline(always)]
     pub fn build_with(ptr: usize) -> Self {
+        debug_assert!(ptr != 0);
         UntypedArenaPtr::new().with_ptr(ptr as u64)
     }
 }
@@ -698,6 +699,7 @@ impl UntypedArenaPtr {
     #[inline]
     pub fn get_tag(self) -> ArenaHeaderTag {
         unsafe {
+            debug_assert!(!self.get_ptr().is_null());
             let header = *(self.get_ptr() as *const ArenaHeader);
             header.get_tag()
         }