From: Skgland Date: Sat, 25 Apr 2026 14:39:53 +0000 (+0200) Subject: fix ArenaPtr payload offset logic X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=eac7ff680ce7a9f95bc88daaa7c0339f2bf494b8;p=scryer-prolog.git fix ArenaPtr payload offset logic 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 --- diff --git a/src/arena.rs b/src/arena.rs index 1b5cd3e5..ffb92fb7 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -283,7 +283,10 @@ pub trait ArenaAllocated { Self::Payload: Sized, { TypedArenaPtr(NonNull::new_unchecked( - ptr.payload_offset().cast_mut().cast::(), + ptr.get_ptr() + .byte_add(Self::header_offset_from_payload()) + .cast_mut() + .cast::(), )) } diff --git a/src/types.rs b/src/types.rs index 994a6a27..bcf67a4a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -754,11 +754,6 @@ impl UntypedArenaPtr { } } - #[inline] - pub fn payload_offset(self) -> *const u8 { - unsafe { self.get_ptr().byte_add(size_of::()).cast() } - } - /// # Safety /// - this UntypedArenaPtr actual pointee type is T /// - the pointer must be non-null