]> Repositorios git - scryer-prolog.git/commitdiff
fix ArenaPtr payload offset logic
authorSkgland <[email protected]>
Sat, 25 Apr 2026 14:39:53 +0000 (16:39 +0200)
committerSkgland <[email protected]>
Sat, 25 Apr 2026 16:12:32 +0000 (18:12 +0200)
the old logic would be incorrect if the payload has higher alignment than the ArenaHeader i.e. when there is padding between the ArenaHeader and the Payload

src/arena.rs
src/types.rs

index 1b5cd3e5a808b37c47b754dd62c3893165b453f2..ffb92fb74c3b3b85713d9fb6ac5090f6f8f6ce14 100644 (file)
@@ -283,7 +283,10 @@ pub trait ArenaAllocated {
         Self::Payload: Sized,
     {
         TypedArenaPtr(NonNull::new_unchecked(
-            ptr.payload_offset().cast_mut().cast::<Self::Payload>(),
+            ptr.get_ptr()
+                .byte_add(Self::header_offset_from_payload())
+                .cast_mut()
+                .cast::<Self::Payload>(),
         ))
     }
 
index 994a6a27dcfc4bebec03967f1cff9225663c1ae8..bcf67a4a01d2b250f42b6585828ad7143abc35a6 100644 (file)
@@ -754,11 +754,6 @@ impl UntypedArenaPtr {
         }
     }
 
-    #[inline]
-    pub fn payload_offset(self) -> *const u8 {
-        unsafe { self.get_ptr().byte_add(size_of::<ArenaHeader>()).cast() }
-    }
-
     /// # Safety
     /// - this UntypedArenaPtr actual pointee type is T
     /// - the pointer must be non-null