Don't access GCed field in finalizer. Fixes #2305
This commit is contained in:
parent
9b0ac8afa8
commit
2130e9e38f
1 changed files with 7 additions and 8 deletions
|
|
@ -22,7 +22,7 @@ type
|
||||||
data: string
|
data: string
|
||||||
sons: seq[TBNode] # directly embedded!
|
sons: seq[TBNode] # directly embedded!
|
||||||
t: TTable
|
t: TTable
|
||||||
|
|
||||||
TCaseKind = enum nkStr, nkWhole, nkList
|
TCaseKind = enum nkStr, nkWhole, nkList
|
||||||
PCaseNode = ref TCaseNode
|
PCaseNode = ref TCaseNode
|
||||||
TCaseNode {.final.} = object
|
TCaseNode {.final.} = object
|
||||||
|
|
@ -33,7 +33,7 @@ type
|
||||||
|
|
||||||
TIdObj* = object of TObject
|
TIdObj* = object of TObject
|
||||||
id*: int # unique id; use this for comparisons and not the pointers
|
id*: int # unique id; use this for comparisons and not the pointers
|
||||||
|
|
||||||
PIdObj* = ref TIdObj
|
PIdObj* = ref TIdObj
|
||||||
PIdent* = ref TIdent
|
PIdent* = ref TIdent
|
||||||
TIdent*{.acyclic.} = object of TIdObj
|
TIdent*{.acyclic.} = object of TIdObj
|
||||||
|
|
@ -53,22 +53,21 @@ proc newCaseNode(data: string): PCaseNode =
|
||||||
result.kind = nkWhole
|
result.kind = nkWhole
|
||||||
result.unused = @["", "abc", "abdc"]
|
result.unused = @["", "abc", "abdc"]
|
||||||
flip = 1 - flip
|
flip = 1 - flip
|
||||||
|
|
||||||
proc newCaseNode(a, b: PCaseNode): PCaseNode =
|
proc newCaseNode(a, b: PCaseNode): PCaseNode =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = nkList
|
result.kind = nkList
|
||||||
result.sons = @[a, b]
|
result.sons = @[a, b]
|
||||||
|
|
||||||
proc caseTree(lvl: int = 0): PCaseNode =
|
proc caseTree(lvl: int = 0): PCaseNode =
|
||||||
if lvl == 3: result = newCaseNode("data item")
|
if lvl == 3: result = newCaseNode("data item")
|
||||||
else: result = newCaseNode(caseTree(lvl+1), caseTree(lvl+1))
|
else: result = newCaseNode(caseTree(lvl+1), caseTree(lvl+1))
|
||||||
|
|
||||||
proc finalizeBNode(n: TBNode) = writeLine(stdout, n.data)
|
|
||||||
proc finalizeNode(n: PNode) =
|
proc finalizeNode(n: PNode) =
|
||||||
assert(n != nil)
|
assert(n != nil)
|
||||||
write(stdout, "finalizing: ")
|
write(stdout, "finalizing: ")
|
||||||
if isNil(n.data): writeLine(stdout, "nil!")
|
if isNil(n.data): writeLine(stdout, "nil!")
|
||||||
else: writeLine(stdout, n.data)
|
else: writeLine(stdout, "not nil")
|
||||||
|
|
||||||
var
|
var
|
||||||
id: int = 1
|
id: int = 1
|
||||||
|
|
@ -147,7 +146,7 @@ proc buildBTree(father: var TBNode) =
|
||||||
father.t.data = @["ha", "lets", "stress", "it"]
|
father.t.data = @["ha", "lets", "stress", "it"]
|
||||||
setSons(father)
|
setSons(father)
|
||||||
|
|
||||||
proc getIdent(identifier: cstring, length: int, h: int): PIdent =
|
proc getIdent(identifier: cstring, length: int, h: int): PIdent =
|
||||||
new(result)
|
new(result)
|
||||||
result.h = h
|
result.h = h
|
||||||
result.s = newString(length)
|
result.s = newString(length)
|
||||||
|
|
@ -157,7 +156,7 @@ proc main() =
|
||||||
discard getIdent("hall", 4, 0)
|
discard getIdent("hall", 4, 0)
|
||||||
discard getIdent("echo", 4, 0)
|
discard getIdent("echo", 4, 0)
|
||||||
discard getIdent("huch", 4, 0)
|
discard getIdent("huch", 4, 0)
|
||||||
|
|
||||||
var
|
var
|
||||||
father: TBNode
|
father: TBNode
|
||||||
for i in 1..1_00:
|
for i in 1..1_00:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue