tunref_cycle.nim 513 B

123456789101112131415161718192021222324252627
  1. discard """
  2. outputsub: '''inside closure
  3. hello world'''
  4. cmd: "nim c --gc:orc -d:useMalloc $file"
  5. valgrind: true
  6. """
  7. # bug #18579
  8. var fp: proc (env: pointer) {.cdecl.}
  9. var env: pointer
  10. proc store(f: proc (){.closure.}) =
  11. proc closeOver() =
  12. echo "inside closure"
  13. f()
  14. (fp,env) = (cast[proc(env: pointer){.cdecl.}](rawProc closeOver), rawEnv closeOver)
  15. GC_ref(cast[RootRef](env))
  16. proc run() =
  17. fp(env)
  18. GC_unref(cast[RootRef](env))
  19. store(proc() = echo "hello world")
  20. run()
  21. GC_fullCollect()