diff options
author | Yuriy Glukhov <yglukhov@users.noreply.github.com> | 2017-07-15 09:50:41 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-07-15 08:50:41 +0200 |
commit | bdf6f59c6d4864d6436f6c517ebab5572d2b937a (patch) | |
tree | 8ac9455bfd6403a99d486897396896ca263bc224 /lib/pure/asyncmacro.nim | |
parent | 8b107972c5535b0031918eb7c0364bde5761d0ac (diff) | |
download | Nim-bdf6f59c6d4864d6436f6c517ebab5572d2b937a.tar.gz |
Fixes #5738 (#6059)
Diffstat (limited to 'lib/pure/asyncmacro.nim')
-rw-r--r-- | lib/pure/asyncmacro.nim | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 89b216b25..82226182a 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -28,7 +28,7 @@ template createCb(retFutureSym, iteratorNameSym, name, futureVarCompletions: untyped) = var nameIterVar = iteratorNameSym #{.push stackTrace: off.} - proc cb {.closure,gcsafe.} = + proc cb {.closure.} = try: if not nameIterVar.finished: var next = nameIterVar() @@ -38,7 +38,8 @@ template createCb(retFutureSym, iteratorNameSym, "`nil` Future?" raise newException(AssertionError, msg % name) else: - next.callback = cb + {.gcsafe.}: + next.callback = (proc() {.closure, gcsafe.})(cb) except: futureVarCompletions @@ -379,7 +380,10 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = procBody, nnkIteratorDef) closureIterator.pragma = newNimNode(nnkPragma, lineInfoFrom=prc.body) closureIterator.addPragma(newIdentNode("closure")) - closureIterator.addPragma(newIdentNode("gcsafe")) + + # If proc has an explicit gcsafe pragma, we add it to iterator as well. + if prc.pragma.findChild(it.kind in {nnkSym, nnkIdent} and $it == "gcsafe") != nil: + closureIterator.addPragma(newIdentNode("gcsafe")) outerProcBody.add(closureIterator) # -> createCb(retFuture) |