diff options
author | Araq <rumpf_a@web.de> | 2019-11-25 15:29:41 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-11-26 16:04:28 +0100 |
commit | 72237e2bcfc371d917e4e14b22a3c447289ea39f (patch) | |
tree | 25922b2b6dc02898657ec9d6399b6c7938e8eb92 /tests | |
parent | 879801c63980287070f64d94e4c4f7aeb28cb2f4 (diff) | |
download | Nim-72237e2bcfc371d917e4e14b22a3c447289ea39f.tar.gz |
ARC: ported the GC tests over to --gc:arc
Diffstat (limited to 'tests')
-rw-r--r-- | tests/destructor/tmisc_destructors.nim | 2 | ||||
-rw-r--r-- | tests/gc/closureleak.nim | 22 | ||||
-rw-r--r-- | tests/gc/cycleleak.nim | 2 | ||||
-rw-r--r-- | tests/gc/gcemscripten.nim | 2 | ||||
-rw-r--r-- | tests/gc/gcleak4.nim | 8 | ||||
-rw-r--r-- | tests/gc/stackrefleak.nim | 3 | ||||
-rw-r--r-- | tests/gc/weakrefs.nim | 9 |
7 files changed, 32 insertions, 16 deletions
diff --git a/tests/destructor/tmisc_destructors.nim b/tests/destructor/tmisc_destructors.nim index 354938392..fdcea074b 100644 --- a/tests/destructor/tmisc_destructors.nim +++ b/tests/destructor/tmisc_destructors.nim @@ -28,7 +28,7 @@ proc test(): auto = var (a, b, _) = test() doAssert assign_counter == 0 -doAssert sink_counter == 12 # + 3 because of the conservative tuple unpacking transformation +doAssert sink_counter == 9 # XXX this is still silly and needs to be investigated # bug #11510 proc main = diff --git a/tests/gc/closureleak.nim b/tests/gc/closureleak.nim index f86a936d8..508004a53 100644 --- a/tests/gc/closureleak.nim +++ b/tests/gc/closureleak.nim @@ -3,20 +3,28 @@ discard """ disabled: "32bit" """ -from strutils import join - type - TFoo * = object + TFoo* = object id: int fn: proc(){.closure.} var foo_counter = 0 var alive_foos = newseq[int](0) -proc free*(some: ref TFoo) = - #echo "Tfoo #", some.id, " freed" - alive_foos.del alive_foos.find(some.id) +when defined(gcDestructors): + proc `=destroy`(some: var TFoo) = + alive_foos.del alive_foos.find(some.id) + `=destroy`(some.fn) + +else: + proc free*(some: ref TFoo) = + #echo "Tfoo #", some.id, " freed" + alive_foos.del alive_foos.find(some.id) + proc newFoo*(): ref TFoo = - new result, free + when defined(gcDestructors): + new result + else: + new result, free result.id = foo_counter alive_foos.add result.id diff --git a/tests/gc/cycleleak.nim b/tests/gc/cycleleak.nim index 9f5c30ebd..e355abc96 100644 --- a/tests/gc/cycleleak.nim +++ b/tests/gc/cycleleak.nim @@ -10,7 +10,7 @@ type PModule = ref Module Node = object - owner*: PModule + owner* {.cursor.}: PModule data*: array[0..200, char] # some fat to drain memory faster id: int diff --git a/tests/gc/gcemscripten.nim b/tests/gc/gcemscripten.nim index bbef13d98..cc12b230f 100644 --- a/tests/gc/gcemscripten.nim +++ b/tests/gc/gcemscripten.nim @@ -15,7 +15,7 @@ when defined(allow_print): else: const print = false -proc myResult3*(i:int):X {.exportc.} = +proc myResult3*(i:int): X {.exportc.} = if print: echo "3" new(result) if print: echo "3-2" diff --git a/tests/gc/gcleak4.nim b/tests/gc/gcleak4.nim index 35b8ce112..aec0218e8 100644 --- a/tests/gc/gcleak4.nim +++ b/tests/gc/gcleak4.nim @@ -2,11 +2,11 @@ discard """ outputsub: "no leak: " """ -when defined(GC_setMaxPause): +when declared(GC_setMaxPause): GC_setMaxPause 2_000 type - TExpr = object {.inheritable.} ## abstract base class for an expression + TExpr {.inheritable.} = object ## abstract base class for an expression PLiteral = ref TLiteral TLiteral = object of TExpr x: int @@ -15,7 +15,7 @@ type a, b: ref TExpr op2: string -method eval(e: ref TExpr): int = +method eval(e: ref TExpr): int {.base.} = # override this base method quit "to override!" @@ -30,7 +30,7 @@ proc newLit(x: int): ref TLiteral = result.x = x result.op1 = $getOccupiedMem() -proc newPlus(a, b: ref TExpr): ref TPlusExpr = +proc newPlus(a, b: sink(ref TExpr)): ref TPlusExpr = new(result) result.a = a result.b = b diff --git a/tests/gc/stackrefleak.nim b/tests/gc/stackrefleak.nim index 302ef3599..7f3fbff43 100644 --- a/tests/gc/stackrefleak.nim +++ b/tests/gc/stackrefleak.nim @@ -12,7 +12,8 @@ type proc makePair: PCyclic = new(result) new(result.sibling) - result.sibling.sibling = result + when not defined(gcDestructors): + result.sibling.sibling = result proc loop = for i in 0..10000: diff --git a/tests/gc/weakrefs.nim b/tests/gc/weakrefs.nim index 0a6d4b873..81c048d74 100644 --- a/tests/gc/weakrefs.nim +++ b/tests/gc/weakrefs.nim @@ -19,8 +19,15 @@ var proc finalizer(x: StrongObject) = valid.excl(x.id) +when defined(gcDestructors): + proc `=destroy`(x: var TMyObject) = + valid.excl(x.id) + proc create: StrongObject = - new(result, finalizer) + when defined(gcDestructors): + new(result) + else: + new(result, finalizer) result.id = gid valid.incl(gid) inc gid |