From 2cd037a4653fa28f79901c48b93512be358316a8 Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 2 Apr 2026 09:35:39 +0200 Subject: [PATCH] better fix --- lib/system/alloc.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 8ca8656e8c..9c2d5c69dd 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -872,10 +872,8 @@ proc rawAlloc(a: var MemRegion, requestedSize: int, alignment: int = 0): pointer inc(a.allocCounter) sysAssert(allocInv(a), "rawAlloc: begin") sysAssert(roundup(65, 8) == 72, "rawAlloc: roundup broken") - var size = roundup(requestedSize, MemAlign) + let size = roundup(requestedSize, max(MemAlign, alignment)) let alignOff = smallChunkAlignOffset(alignment) - if alignment > MemAlign: - size = roundup(size, alignment) sysAssert(size >= sizeof(FreeCell), "rawAlloc: requested size too small") sysAssert(size >= requestedSize, "insufficient allocated size!") #c_fprintf(stdout, "alloc; size: %ld; %ld\n", requestedSize, size) @@ -979,7 +977,7 @@ proc rawAlloc(a: var MemRegion, requestedSize: int, alignment: int = 0): pointer # Since chunks are page-aligned, the needed padding is a compile-time # deterministic value rather than a worst-case estimate. let alignPad = bigChunkAlignOffset(alignment) - size = requestedSize + bigChunkOverhead() + alignPad + let size = requestedSize + bigChunkOverhead() + alignPad # allocate a large block var c = if size >= HugeChunkSize: getHugeChunk(a, size) else: getBigChunk(a, size)