injectdestructors fixes and refactor (#14964)
* injectdestructors fixes and refactor * Tiny cleanup * Refactor and expand testcase * Closes #14902 by adding testcase * Better naming * Fix test failures * Misc cleanup * Add testcase for #14968 * Better approach; expand testcases * Optimizations and fixes * Add testcase * typo * Tiny cleanup
This commit is contained in:
parent
f999f916f3
commit
2b0e336c97
6 changed files with 317 additions and 198 deletions
|
|
@ -3,6 +3,11 @@ discard """
|
|||
123xyzabc
|
||||
destroyed: false
|
||||
destroyed: false
|
||||
destroyed2: false
|
||||
destroyed2: false
|
||||
destroying variable: 2
|
||||
destroying variable: 1
|
||||
whiley ends :(
|
||||
1
|
||||
(x: "0")
|
||||
(x: "1")
|
||||
|
|
@ -17,7 +22,8 @@ destroyed: false
|
|||
(x: "10")
|
||||
0
|
||||
closed
|
||||
destroying variable
|
||||
destroying variable: 20
|
||||
destroying variable: 10
|
||||
'''
|
||||
cmd: "nim c --gc:arc $file"
|
||||
"""
|
||||
|
|
@ -40,11 +46,12 @@ type Variable = ref object
|
|||
value: int
|
||||
|
||||
proc `=destroy`(self: var typeof(Variable()[])) =
|
||||
echo "destroying variable"
|
||||
echo "destroying variable: ",self.value
|
||||
|
||||
proc newVariable(value: int): Variable =
|
||||
result = Variable()
|
||||
result.value = value
|
||||
#echo "creating variable: ",result.value
|
||||
|
||||
proc test(count: int) =
|
||||
var v {.global.} = newVariable(10)
|
||||
|
|
@ -57,6 +64,28 @@ proc test(count: int) =
|
|||
|
||||
test(3)
|
||||
|
||||
proc test2(count: int) =
|
||||
#block: #XXX: Fails with block currently
|
||||
var v {.global.} = newVariable(20)
|
||||
|
||||
var count = count - 1
|
||||
if count == 0: return
|
||||
|
||||
test2(count)
|
||||
echo "destroyed2: ", v.isNil
|
||||
|
||||
test2(3)
|
||||
|
||||
proc whiley =
|
||||
var a = newVariable(1)
|
||||
while true:
|
||||
var b = newVariable(2)
|
||||
if true: raise newException(CatchableError, "test")
|
||||
|
||||
try:
|
||||
whiley()
|
||||
except CatchableError:
|
||||
echo "whiley ends :("
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# issue #13810
|
||||
|
|
@ -209,3 +238,8 @@ proc setParent(self: SimpleLoopB, parent: SimpleLoopB) =
|
|||
|
||||
var l = SimpleLoopB()
|
||||
l.setParent(l)
|
||||
|
||||
|
||||
# bug #14968
|
||||
import times
|
||||
let currentTime = now().utc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue