From 56fce26f61d1db48c0dc9497dd78ea2b8966916f Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:26:18 +0800 Subject: [PATCH] refactor memory management structures for consistency across modules --- lib/system/alloc.nim | 2 ++ lib/system/cellsets.nim | 16 ++++++++++++++++ lib/system/mmdisp.nim | 20 +------------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 1c2706120e..77025265f1 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -104,6 +104,8 @@ type zeroField: int # 0 means cell is not used (overlaid with typ field) # 1 means cell is manually managed pointer # otherwise a PNimType is stored in there + when sizeof(int) == 4: # 32-bit only + headerAlignPad: array[8, byte] # so addr(data) ≡ 8 (mod 16) else: alignment: int diff --git a/lib/system/cellsets.nim b/lib/system/cellsets.nim index 80f0367019..07bf440753 100644 --- a/lib/system/cellsets.nim +++ b/lib/system/cellsets.nim @@ -48,7 +48,23 @@ when defined(gcOrc) or defined(gcArc) or defined(gcAtomicArc) or defined(gcYrc): when not declaredInScope(PageShift): include bitmasks +else: + type + RefCount = int + Cell {.pure.} = object + refcount: RefCount # the refcount and some flags + typ: PNimType + + when trackAllocationSource: + filename: cstring + line: int + elif useCellIds: + id: int + elif defined(cpu32): + headerAlignPad: array[8, byte] # so addr(data) ≡ 8 (mod 16) + + PCell = ptr Cell type PPageDesc = ptr PageDesc diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index 0f3a154b8e..3caa41d03c 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -38,24 +38,6 @@ type PByte = ptr ByteArray PString = ptr string -when not defined(nimV2): - type - RefCount = int - - Cell {.pure.} = object - refcount: RefCount # the refcount and some flags - typ: PNimType - when sizeof(int) == 4: # 32-bit only - headerAlignPad: array[8, byte] # so addr(data) ≡ 8 (mod 16) - - when trackAllocationSource: - filename: cstring - line: int - when useCellIds: - id: int - - PCell = ptr Cell - when declared(IntsPerTrunk): discard else: @@ -96,7 +78,7 @@ else: when not usesDestructors: include "system/cellsets" when not leakDetector and not useCellIds and not defined(nimV2): - sysAssert(sizeof(FreeCell) <= sizeof(Cell), "sizeof FreeCell") + sysAssert(sizeof(FreeCell) == sizeof(Cell), "sizeof FreeCell") when defined(gcRegions): # XXX due to bootstrapping reasons, we cannot use compileOption("gc", "stack") here include "system/gc_regions"