diff options
author | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2015-08-24 15:28:11 +0300 |
---|---|---|
committer | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2015-08-24 15:29:59 +0300 |
commit | 2130e9e38f6054744cc4c6dcb55da54a5fcc9845 (patch) | |
tree | 5e5b673bdae1deb0340d4a657576bb307fe4a556 /tests | |
parent | 9b0ac8afa88272b03247199844018758fada6958 (diff) | |
download | Nim-2130e9e38f6054744cc4c6dcb55da54a5fcc9845.tar.gz |
Don't access GCed field in finalizer. Fixes #2305
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gc/gctest.nim | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/gc/gctest.nim b/tests/gc/gctest.nim index a634a47f2..b3b9af608 100644 --- a/tests/gc/gctest.nim +++ b/tests/gc/gctest.nim @@ -22,7 +22,7 @@ type data: string sons: seq[TBNode] # directly embedded! t: TTable - + TCaseKind = enum nkStr, nkWhole, nkList PCaseNode = ref TCaseNode TCaseNode {.final.} = object @@ -33,7 +33,7 @@ type TIdObj* = object of TObject id*: int # unique id; use this for comparisons and not the pointers - + PIdObj* = ref TIdObj PIdent* = ref TIdent TIdent*{.acyclic.} = object of TIdObj @@ -53,22 +53,21 @@ proc newCaseNode(data: string): PCaseNode = result.kind = nkWhole result.unused = @["", "abc", "abdc"] flip = 1 - flip - + proc newCaseNode(a, b: PCaseNode): PCaseNode = new(result) result.kind = nkList result.sons = @[a, b] - + proc caseTree(lvl: int = 0): PCaseNode = if lvl == 3: result = newCaseNode("data item") else: result = newCaseNode(caseTree(lvl+1), caseTree(lvl+1)) -proc finalizeBNode(n: TBNode) = writeLine(stdout, n.data) proc finalizeNode(n: PNode) = assert(n != nil) write(stdout, "finalizing: ") if isNil(n.data): writeLine(stdout, "nil!") - else: writeLine(stdout, n.data) + else: writeLine(stdout, "not nil") var id: int = 1 @@ -147,7 +146,7 @@ proc buildBTree(father: var TBNode) = father.t.data = @["ha", "lets", "stress", "it"] setSons(father) -proc getIdent(identifier: cstring, length: int, h: int): PIdent = +proc getIdent(identifier: cstring, length: int, h: int): PIdent = new(result) result.h = h result.s = newString(length) @@ -157,7 +156,7 @@ proc main() = discard getIdent("hall", 4, 0) discard getIdent("echo", 4, 0) discard getIdent("huch", 4, 0) - + var father: TBNode for i in 1..1_00: |