summary refs log tree commit diff stats
path: root/tests/gc/closureleak.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gc/closureleak.nim')
-rw-r--r--tests/gc/closureleak.nim41
1 files changed, 30 insertions, 11 deletions
diff --git a/tests/gc/closureleak.nim b/tests/gc/closureleak.nim
index 18d320bdf..e67beb513 100644
--- a/tests/gc/closureleak.nim
+++ b/tests/gc/closureleak.nim
@@ -1,30 +1,49 @@
 discard """
   outputsub: "true"
+  disabled: "32bit"
 """
 
-from strutils import join
-
 type
-  TFoo * = object
+  TFoo* = object
     id: int
-    fn: proc(){.closure.}
+    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: TFoo) =
+    alive_foos.del alive_foos.find(some.id)
+    # TODO: fixme: investigate why `=destroy` requires `some.fn` to be `gcsafe`
+    # the debugging info below came from `symPrototype` in the liftdestructors
+    # proc (){.closure, gcsafe.}, {tfThread, tfHasAsgn, tfCheckedForDestructor, tfExplicitCallConv}
+    # var proc (){.closure, gcsafe.}, {tfHasGCedMem}
+    # it worked by accident with var T destructors because in the sempass2
+    #
+    # let argtype = skipTypes(a.typ, abstractInst) # !!! it does't skip `tyVar`
+    # if argtype.kind == tyProc and notGcSafe(argtype) and not tracked.inEnforcedGcSafe:
+    #   localError(tracked.config, n.info, $n & " is not GC safe")
+    {.cast(gcsafe).}:
+      `=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
   inc foo_counter
 
-for i in 0 .. <10:
- discard newFoo()
+for i in 0 ..< 10:
+  discard newFoo()
 
-for i in 0 .. <10:
+for i in 0 ..< 10:
   let f = newFoo()
   f.fn = proc =
     echo f.id