hotfix for --gc:regions

This commit is contained in:
Andreas Rumpf 2018-05-28 11:24:29 +02:00
commit 3221ac0943
2 changed files with 12 additions and 6 deletions

View file

@ -162,6 +162,7 @@ proc allocFast(r: var MemRegion; size: int): pointer =
return pointer(it) return pointer(it)
prev = it prev = it
it = it.next it = it.next
let size = roundup(size, MemAlign)
if size > r.remaining: if size > r.remaining:
allocSlowPath(r, size) allocSlowPath(r, size)
sysAssert(size <= r.remaining, "size <= r.remaining") sysAssert(size <= r.remaining, "size <= r.remaining")
@ -288,11 +289,13 @@ proc rawNewSeq(r: var MemRegion, typ: PNimType, size: int): pointer =
result = res +! sizeof(SeqHeader) result = res +! sizeof(SeqHeader)
proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} = proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} =
sysAssert typ.kind notin {tySequence, tyString}, "newObj cannot be used to construct seqs"
result = rawNewObj(tlRegion, typ, size) result = rawNewObj(tlRegion, typ, size)
zeroMem(result, size) zeroMem(result, size)
when defined(memProfiler): nimProfile(size) when defined(memProfiler): nimProfile(size)
proc newObjNoInit(typ: PNimType, size: int): pointer {.compilerRtl.} = proc newObjNoInit(typ: PNimType, size: int): pointer {.compilerRtl.} =
sysAssert typ.kind notin {tySequence, tyString}, "newObj cannot be used to construct seqs"
result = rawNewObj(tlRegion, typ, size) result = rawNewObj(tlRegion, typ, size)
when defined(memProfiler): nimProfile(size) when defined(memProfiler): nimProfile(size)

View file

@ -561,13 +561,16 @@ else:
when not declared(nimNewSeqOfCap): when not declared(nimNewSeqOfCap):
proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} = proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} =
let s = addInt(mulInt(cap, typ.base.size), GenericSeqSize) when defined(gcRegions):
when declared(newObjNoInit): result = newStr(typ, cap, ntfNoRefs notin typ.base.flags)
result = if ntfNoRefs in typ.base.flags: newObjNoInit(typ, s) else: newObj(typ, s)
else: else:
result = newObj(typ, s) let s = addInt(mulInt(cap, typ.base.size), GenericSeqSize)
cast[PGenericSeq](result).len = 0 when declared(newObjNoInit):
cast[PGenericSeq](result).reserved = cap result = if ntfNoRefs in typ.base.flags: newObjNoInit(typ, s) else: newObj(typ, s)
else:
result = newObj(typ, s)
cast[PGenericSeq](result).len = 0
cast[PGenericSeq](result).reserved = cap
{.pop.} {.pop.}