mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
cleaned up GC tests; fixes object variant re-assign bug
This commit is contained in:
@@ -27,7 +27,7 @@ proc genericAssignAux(dest, src: pointer, n: ptr TNimNode,
|
||||
var m = selectBranch(src, n)
|
||||
# reset if different branches are in use; note different branches also
|
||||
# imply that's not self-assignment (``x = x``)!
|
||||
if m != dd and dd != nil:
|
||||
if m != dd and dd != nil:
|
||||
genericResetAux(dest, dd)
|
||||
copyMem(cast[pointer](d +% n.offset), cast[pointer](s +% n.offset),
|
||||
n.typ.size)
|
||||
@@ -205,9 +205,13 @@ proc genericReset(dest: pointer, mt: PNimType) =
|
||||
case mt.kind
|
||||
of tyString, tyRef, tySequence:
|
||||
unsureAsgnRef(cast[PPointer](dest), nil)
|
||||
of tyObject, tyTuple:
|
||||
# we don't need to reset m_type field for tyObject
|
||||
of tyTuple:
|
||||
genericResetAux(dest, mt.node)
|
||||
of tyObject:
|
||||
genericResetAux(dest, mt.node)
|
||||
# also reset the type field for tyObject, for correct branch switching!
|
||||
var pint = cast[ptr PNimType](dest)
|
||||
pint[] = nil
|
||||
of tyArray, tyArrayConstr:
|
||||
for i in 0..(mt.size div mt.base.size)-1:
|
||||
genericReset(cast[pointer](d +% i*% mt.base.size), mt.base)
|
||||
|
||||
@@ -38,12 +38,14 @@ proc newPlus(a, b: ref TExpr): ref TPlusExpr =
|
||||
result.b = b
|
||||
result.op2 = $getOccupiedMem()
|
||||
|
||||
const Limit = when compileOption("gc", "markAndSweep"): 5*1024*1024 else: 500_000
|
||||
|
||||
for i in 0..100_000:
|
||||
var s: array[0..11, ref TExpr]
|
||||
for j in 0..high(s):
|
||||
s[j] = newPlus(newPlus(newLit(j), newLit(2)), newLit(4))
|
||||
if eval(s[j]) != j+6:
|
||||
quit "error: wrong result"
|
||||
if getOccupiedMem() > 500_000: quit("still a leak!")
|
||||
if getOccupiedMem() > Limit: quit("still a leak!")
|
||||
|
||||
echo "no leak: ", getOccupiedMem()
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -5,6 +5,7 @@ version 0.10.4
|
||||
- improve GC-unsafety warnings
|
||||
- get rid of 'mget'; aka priority of 'var' needs to be 'var{lvalue}'
|
||||
- improve documentation (theindex!)
|
||||
- ensure (ref T)(a, b) works as a type conversion and type constructor
|
||||
|
||||
|
||||
version 1.0
|
||||
@@ -66,7 +67,6 @@ version 0.9.x
|
||||
- memory manager: add a measure of fragmentation
|
||||
- implement 'bits' pragmas
|
||||
- we need a magic thisModule symbol
|
||||
- ensure (ref T)(a, b) works as a type conversion and type constructor
|
||||
- optimize 'genericReset'; 'newException' leads to code bloat
|
||||
- The 'do' notation might be trimmed so that its only purpose is to pass
|
||||
multiple multi line constructs to a macro.
|
||||
|
||||
Reference in New Issue
Block a user