fixes --gc:none regression; made some tests green
This commit is contained in:
parent
1efb5174f2
commit
ee57bb3e3e
7 changed files with 49 additions and 41 deletions
|
|
@ -461,6 +461,9 @@ proc rawNewObj(typ: PNimType, size: int, gch: var TGcHeap): pointer =
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
proc newObjNoInit(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
||||||
|
result = rawNewObj(typ, size, gch)
|
||||||
|
|
||||||
proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
||||||
result = rawNewObj(typ, size, gch)
|
result = rawNewObj(typ, size, gch)
|
||||||
zeroMem(result, size)
|
zeroMem(result, size)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nim's Runtime Library
|
# Nim's Runtime Library
|
||||||
# (c) Copyright 2013 Andreas Rumpf
|
# (c) Copyright 2015 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -23,7 +23,7 @@ const
|
||||||
leakDetector = false
|
leakDetector = false
|
||||||
overwriteFree = false
|
overwriteFree = false
|
||||||
trackAllocationSource = leakDetector
|
trackAllocationSource = leakDetector
|
||||||
|
|
||||||
cycleGC = true # (de)activate the cycle GC
|
cycleGC = true # (de)activate the cycle GC
|
||||||
reallyDealloc = true # for debugging purposes this can be set to false
|
reallyDealloc = true # for debugging purposes this can be set to false
|
||||||
reallyOsDealloc = true
|
reallyOsDealloc = true
|
||||||
|
|
@ -71,13 +71,13 @@ when defined(boehmgc):
|
||||||
const boehmLib = "libgc.dylib"
|
const boehmLib = "libgc.dylib"
|
||||||
else:
|
else:
|
||||||
const boehmLib = "/usr/lib/libgc.so.1"
|
const boehmLib = "/usr/lib/libgc.so.1"
|
||||||
|
|
||||||
proc boehmGCinit {.importc: "GC_init", dynlib: boehmLib.}
|
proc boehmGCinit {.importc: "GC_init", dynlib: boehmLib.}
|
||||||
proc boehmGC_disable {.importc: "GC_disable", dynlib: boehmLib.}
|
proc boehmGC_disable {.importc: "GC_disable", dynlib: boehmLib.}
|
||||||
proc boehmGC_enable {.importc: "GC_enable", dynlib: boehmLib.}
|
proc boehmGC_enable {.importc: "GC_enable", dynlib: boehmLib.}
|
||||||
proc boehmGCincremental {.
|
proc boehmGCincremental {.
|
||||||
importc: "GC_enable_incremental", dynlib: boehmLib.}
|
importc: "GC_enable_incremental", dynlib: boehmLib.}
|
||||||
proc boehmGCfullCollect {.importc: "GC_gcollect", dynlib: boehmLib.}
|
proc boehmGCfullCollect {.importc: "GC_gcollect", dynlib: boehmLib.}
|
||||||
proc boehmAlloc(size: int): pointer {.
|
proc boehmAlloc(size: int): pointer {.
|
||||||
importc: "GC_malloc", dynlib: boehmLib.}
|
importc: "GC_malloc", dynlib: boehmLib.}
|
||||||
proc boehmAllocAtomic(size: int): pointer {.
|
proc boehmAllocAtomic(size: int): pointer {.
|
||||||
|
|
@ -85,7 +85,7 @@ when defined(boehmgc):
|
||||||
proc boehmRealloc(p: pointer, size: int): pointer {.
|
proc boehmRealloc(p: pointer, size: int): pointer {.
|
||||||
importc: "GC_realloc", dynlib: boehmLib.}
|
importc: "GC_realloc", dynlib: boehmLib.}
|
||||||
proc boehmDealloc(p: pointer) {.importc: "GC_free", dynlib: boehmLib.}
|
proc boehmDealloc(p: pointer) {.importc: "GC_free", dynlib: boehmLib.}
|
||||||
|
|
||||||
proc boehmGetHeapSize: int {.importc: "GC_get_heap_size", dynlib: boehmLib.}
|
proc boehmGetHeapSize: int {.importc: "GC_get_heap_size", dynlib: boehmLib.}
|
||||||
## Return the number of bytes in the heap. Excludes collector private
|
## Return the number of bytes in the heap. Excludes collector private
|
||||||
## data structures. Includes empty blocks and fragmentation loss.
|
## data structures. Includes empty blocks and fragmentation loss.
|
||||||
|
|
@ -108,7 +108,7 @@ when defined(boehmgc):
|
||||||
zeroMem(result, size)
|
zeroMem(result, size)
|
||||||
|
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
|
|
||||||
proc alloc(size: int): pointer =
|
proc alloc(size: int): pointer =
|
||||||
result = boehmAlloc(size)
|
result = boehmAlloc(size)
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
|
|
@ -119,7 +119,7 @@ when defined(boehmgc):
|
||||||
result = boehmRealloc(p, newsize)
|
result = boehmRealloc(p, newsize)
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
proc dealloc(p: pointer) = boehmDealloc(p)
|
proc dealloc(p: pointer) = boehmDealloc(p)
|
||||||
|
|
||||||
proc allocShared(size: int): pointer =
|
proc allocShared(size: int): pointer =
|
||||||
result = boehmAlloc(size)
|
result = boehmAlloc(size)
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
|
|
@ -148,14 +148,14 @@ when defined(boehmgc):
|
||||||
proc GC_enableMarkAndSweep() = discard
|
proc GC_enableMarkAndSweep() = discard
|
||||||
proc GC_disableMarkAndSweep() = discard
|
proc GC_disableMarkAndSweep() = discard
|
||||||
proc GC_getStatistics(): string = return ""
|
proc GC_getStatistics(): string = return ""
|
||||||
|
|
||||||
proc getOccupiedMem(): int = return boehmGetHeapSize()-boehmGetFreeBytes()
|
proc getOccupiedMem(): int = return boehmGetHeapSize()-boehmGetFreeBytes()
|
||||||
proc getFreeMem(): int = return boehmGetFreeBytes()
|
proc getFreeMem(): int = return boehmGetFreeBytes()
|
||||||
proc getTotalMem(): int = return boehmGetHeapSize()
|
proc getTotalMem(): int = return boehmGetHeapSize()
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc setStackBottom(theStackBottom: pointer) = discard
|
||||||
|
|
||||||
proc initGC() =
|
proc initGC() =
|
||||||
when defined(macosx): boehmGCinit()
|
when defined(macosx): boehmGCinit()
|
||||||
|
|
||||||
proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
||||||
|
|
@ -171,7 +171,7 @@ when defined(boehmgc):
|
||||||
|
|
||||||
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
|
|
||||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||||
dest[] = src
|
dest[] = src
|
||||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||||
|
|
@ -181,20 +181,20 @@ when defined(boehmgc):
|
||||||
|
|
||||||
type
|
type
|
||||||
TMemRegion = object {.final, pure.}
|
TMemRegion = object {.final, pure.}
|
||||||
|
|
||||||
proc alloc(r: var TMemRegion, size: int): pointer =
|
proc alloc(r: var TMemRegion, size: int): pointer =
|
||||||
result = boehmAlloc(size)
|
result = boehmAlloc(size)
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
proc alloc0(r: var TMemRegion, size: int): pointer =
|
proc alloc0(r: var TMemRegion, size: int): pointer =
|
||||||
result = alloc(size)
|
result = alloc(size)
|
||||||
zeroMem(result, size)
|
zeroMem(result, size)
|
||||||
proc dealloc(r: var TMemRegion, p: pointer) = boehmDealloc(p)
|
proc dealloc(r: var TMemRegion, p: pointer) = boehmDealloc(p)
|
||||||
proc deallocOsPages(r: var TMemRegion) {.inline.} = discard
|
proc deallocOsPages(r: var TMemRegion) {.inline.} = discard
|
||||||
proc deallocOsPages() {.inline.} = discard
|
proc deallocOsPages() {.inline.} = discard
|
||||||
|
|
||||||
include "system/cellsets"
|
include "system/cellsets"
|
||||||
elif defined(nogc) and defined(useMalloc):
|
elif defined(nogc) and defined(useMalloc):
|
||||||
|
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
proc alloc(size: int): pointer =
|
proc alloc(size: int): pointer =
|
||||||
result = cmalloc(size)
|
result = cmalloc(size)
|
||||||
|
|
@ -206,7 +206,7 @@ elif defined(nogc) and defined(useMalloc):
|
||||||
result = crealloc(p, newsize)
|
result = crealloc(p, newsize)
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
proc dealloc(p: pointer) = cfree(p)
|
proc dealloc(p: pointer) = cfree(p)
|
||||||
|
|
||||||
proc allocShared(size: int): pointer =
|
proc allocShared(size: int): pointer =
|
||||||
result = cmalloc(size)
|
result = cmalloc(size)
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
|
|
@ -225,11 +225,11 @@ elif defined(nogc) and defined(useMalloc):
|
||||||
proc GC_enableMarkAndSweep() = discard
|
proc GC_enableMarkAndSweep() = discard
|
||||||
proc GC_disableMarkAndSweep() = discard
|
proc GC_disableMarkAndSweep() = discard
|
||||||
proc GC_getStatistics(): string = return ""
|
proc GC_getStatistics(): string = return ""
|
||||||
|
|
||||||
proc getOccupiedMem(): int = discard
|
proc getOccupiedMem(): int = discard
|
||||||
proc getFreeMem(): int = discard
|
proc getFreeMem(): int = discard
|
||||||
proc getTotalMem(): int = discard
|
proc getTotalMem(): int = discard
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc setStackBottom(theStackBottom: pointer) = discard
|
||||||
|
|
||||||
proc initGC() = discard
|
proc initGC() = discard
|
||||||
|
|
@ -240,13 +240,15 @@ elif defined(nogc) and defined(useMalloc):
|
||||||
result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
|
result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
|
||||||
cast[PGenericSeq](result).len = len
|
cast[PGenericSeq](result).len = len
|
||||||
cast[PGenericSeq](result).reserved = len
|
cast[PGenericSeq](result).reserved = len
|
||||||
|
proc newObjNoInit(typ: PNimType, size: int): pointer =
|
||||||
|
result = alloc(size)
|
||||||
|
|
||||||
proc growObj(old: pointer, newsize: int): pointer =
|
proc growObj(old: pointer, newsize: int): pointer =
|
||||||
result = realloc(old, newsize)
|
result = realloc(old, newsize)
|
||||||
|
|
||||||
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
|
|
||||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||||
dest[] = src
|
dest[] = src
|
||||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||||
|
|
@ -256,7 +258,7 @@ elif defined(nogc) and defined(useMalloc):
|
||||||
|
|
||||||
type
|
type
|
||||||
TMemRegion = object {.final, pure.}
|
TMemRegion = object {.final, pure.}
|
||||||
|
|
||||||
proc alloc(r: var TMemRegion, size: int): pointer =
|
proc alloc(r: var TMemRegion, size: int): pointer =
|
||||||
result = alloc(size)
|
result = alloc(size)
|
||||||
proc alloc0(r: var TMemRegion, size: int): pointer =
|
proc alloc0(r: var TMemRegion, size: int): pointer =
|
||||||
|
|
@ -272,9 +274,9 @@ elif defined(nogc):
|
||||||
# object, because C does not support this operation... Even though every
|
# object, because C does not support this operation... Even though every
|
||||||
# possible implementation has to have a way to determine the object's size.
|
# possible implementation has to have a way to determine the object's size.
|
||||||
# C just sucks.
|
# C just sucks.
|
||||||
when appType == "lib":
|
when appType == "lib":
|
||||||
{.warning: "nogc in a library context may not work".}
|
{.warning: "nogc in a library context may not work".}
|
||||||
|
|
||||||
include "system/alloc"
|
include "system/alloc"
|
||||||
|
|
||||||
proc initGC() = discard
|
proc initGC() = discard
|
||||||
|
|
@ -285,10 +287,14 @@ elif defined(nogc):
|
||||||
proc GC_enableMarkAndSweep() = discard
|
proc GC_enableMarkAndSweep() = discard
|
||||||
proc GC_disableMarkAndSweep() = discard
|
proc GC_disableMarkAndSweep() = discard
|
||||||
proc GC_getStatistics(): string = return ""
|
proc GC_getStatistics(): string = return ""
|
||||||
|
|
||||||
|
|
||||||
proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
||||||
result = alloc0(size)
|
result = alloc0(size)
|
||||||
|
|
||||||
|
proc newObjNoInit(typ: PNimType, size: int): pointer =
|
||||||
|
result = alloc(size)
|
||||||
|
|
||||||
proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
|
proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
|
||||||
result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
|
result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
|
||||||
cast[PGenericSeq](result).len = len
|
cast[PGenericSeq](result).len = len
|
||||||
|
|
@ -299,7 +305,7 @@ elif defined(nogc):
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc setStackBottom(theStackBottom: pointer) = discard
|
||||||
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
|
|
||||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||||
dest[] = src
|
dest[] = src
|
||||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||||
|
|
@ -327,6 +333,6 @@ else:
|
||||||
include "system/gc"
|
include "system/gc"
|
||||||
else:
|
else:
|
||||||
include "system/gc"
|
include "system/gc"
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ else:
|
||||||
cast[NimString](newObj(addr(strDesc), size))
|
cast[NimString](newObj(addr(strDesc), size))
|
||||||
|
|
||||||
template allocStrNoInit(size: expr): expr =
|
template allocStrNoInit(size: expr): expr =
|
||||||
cast[NimString](rawNewObj(addr(strDesc), size, gch))
|
cast[NimString](newObjNoInit(addr(strDesc), size))
|
||||||
|
|
||||||
proc rawNewStringNoInit(space: int): NimString {.compilerProc.} =
|
proc rawNewStringNoInit(space: int): NimString {.compilerProc.} =
|
||||||
var s = space
|
var s = space
|
||||||
|
|
@ -215,7 +215,7 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||||
GenericSeqSize))
|
GenericSeqSize))
|
||||||
elif newLen < result.len:
|
elif newLen < result.len:
|
||||||
# we need to decref here, otherwise the GC leaks!
|
# we need to decref here, otherwise the GC leaks!
|
||||||
when not defined(boehmGC) and not defined(nogc) and
|
when not defined(boehmGC) and not defined(nogc) and
|
||||||
not defined(gcMarkAndSweep):
|
not defined(gcMarkAndSweep):
|
||||||
when compileOption("gc", "v2"):
|
when compileOption("gc", "v2"):
|
||||||
for i in newLen..result.len-1:
|
for i in newLen..result.len-1:
|
||||||
|
|
@ -232,7 +232,7 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||||
forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
|
forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
|
||||||
GenericSeqSize +% (i*%elemSize)),
|
GenericSeqSize +% (i*%elemSize)),
|
||||||
extGetCellType(result).base, waZctDecRef)
|
extGetCellType(result).base, waZctDecRef)
|
||||||
|
|
||||||
# XXX: zeroing out the memory can still result in crashes if a wiped-out
|
# XXX: zeroing out the memory can still result in crashes if a wiped-out
|
||||||
# cell is aliased by another pointer (ie proc parameter or a let variable).
|
# cell is aliased by another pointer (ie proc parameter or a let variable).
|
||||||
# This is a tought problem, because even if we don't zeroMem here, in the
|
# This is a tought problem, because even if we don't zeroMem here, in the
|
||||||
|
|
@ -270,7 +270,7 @@ proc nimFloatToStr(f: float): string {.compilerproc.} =
|
||||||
if buf[i] == ',':
|
if buf[i] == ',':
|
||||||
buf[i] = '.'
|
buf[i] = '.'
|
||||||
hasDot = true
|
hasDot = true
|
||||||
elif buf[i] in {'a'..'z', 'A'..'Z', '.'}:
|
elif buf[i] in {'a'..'z', 'A'..'Z', '.'}:
|
||||||
hasDot = true
|
hasDot = true
|
||||||
if not hasDot:
|
if not hasDot:
|
||||||
buf[n] = '.'
|
buf[n] = '.'
|
||||||
|
|
@ -321,7 +321,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
template addToBuf(c) =
|
template addToBuf(c) =
|
||||||
if ti < t.high:
|
if ti < t.high:
|
||||||
t[ti] = c; inc(ti)
|
t[ti] = c; inc(ti)
|
||||||
|
|
||||||
# Sign?
|
# Sign?
|
||||||
if s[i] == '+' or s[i] == '-':
|
if s[i] == '+' or s[i] == '-':
|
||||||
if s[i] == '-':
|
if s[i] == '-':
|
||||||
|
|
@ -342,7 +342,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
if s[i] == 'I' or s[i] == 'i':
|
if s[i] == 'I' or s[i] == 'i':
|
||||||
if s[i+1] == 'N' or s[i+1] == 'n':
|
if s[i+1] == 'N' or s[i+1] == 'n':
|
||||||
if s[i+2] == 'F' or s[i+2] == 'f':
|
if s[i+2] == 'F' or s[i+2] == 'f':
|
||||||
if s[i+3] notin IdentChars:
|
if s[i+3] notin IdentChars:
|
||||||
number = Inf*sign
|
number = Inf*sign
|
||||||
return i+3 - start
|
return i+3 - start
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
discard """
|
discard """
|
||||||
nimout: "'a' is deprecated [Deprecated]"
|
nimout: "a is deprecated [Deprecated]"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var
|
var
|
||||||
a {.deprecated.}: array[0..11, int]
|
a {.deprecated.}: array[0..11, int]
|
||||||
|
|
||||||
a[8] = 1
|
a[8] = 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
line: 7
|
line: 7
|
||||||
errormsg: "expression 'items' cannot be called"
|
errormsg: "undeclared identifier: 'items'"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type a = enum b,c,d
|
type a = enum b,c,d
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tissue710.nim"
|
file: "tissue710.nim"
|
||||||
line: 8
|
line: 8
|
||||||
errorMsg: "expression '||' cannot be called"
|
errorMsg: "undeclared identifier: '||'"
|
||||||
"""
|
"""
|
||||||
var sum = 0
|
var sum = 0
|
||||||
for x in 3..1000:
|
for x in 3..1000:
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tnoop.nim"
|
file: "tnoop.nim"
|
||||||
line: 11
|
line: 11
|
||||||
errormsg: "expression \'a()\' cannot be called"
|
errormsg: "undeclared identifier: 'a'"
|
||||||
"""
|
"""
|
||||||
# Tests the new check in the semantic pass
|
|
||||||
|
|
||||||
var
|
var
|
||||||
a: int
|
a: int
|
||||||
|
|
||||||
a() #ERROR_MSG expression 'a()' cannot be called
|
a()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue