correct pointer alignment on decref

This commit is contained in:
Brendan Hansknecht 2024-07-12 17:52:50 -07:00
parent d4b86a745b
commit 4e8f916204
No known key found for this signature in database
GPG key ID: 0EA784685083E75B

View file

@ -337,7 +337,7 @@ inline fn free_ptr_to_refcount(
inline fn decref_ptr_to_refcount(
refcount_ptr: [*]isize,
alignment: u32,
element_alignment: u32,
elements_refcounted: bool,
) void {
if (RC_TYPE == Refcount.none) return;
@ -346,6 +346,10 @@ inline fn decref_ptr_to_refcount(
std.debug.print("| decrement {*}: ", .{refcount_ptr});
}
// Due to RC alignmen tmust take into acount pointer size.
const ptr_width = @sizeOf(usize);
const alignment = @max(ptr_width, element_alignment);
// Ensure that the refcount is not whole program lifetime.
const refcount: isize = refcount_ptr[0];
if (refcount != REFCOUNT_MAX_ISIZE) {