From d59b9a21689d82d424b7be0d699ccbf3ba538d31 Mon Sep 17 00:00:00 2001 From: Reimer Behrends Date: Thu, 14 Aug 2014 03:09:39 +0200 Subject: [PATCH 1/2] Fix stack bottom initialization for non-main modules. Because PreMain() was now called before the new stack bottom initialization, it still relied on the old version of initStackBottom(), which may not handle the top few words of the stack correctly. This patch also sets the stack bottom in PreMain() using the new approach. --- compiler/cgen.nim | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 112a2af34d..2d3831a15a 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -949,12 +949,23 @@ proc genFilenames(m: BModule): PRope = proc genMainProc(m: BModule) = const + # The use of a volatile function pointer to call Pre/NimMainInner + # prevents inlining of the NimMainInner function and dependent + # functions, which might otherwise merge their stack frames. PreMainBody = - "\tsystemDatInit();$N" & + "void PreMainInner() {$N" & "\tsystemInit();$N" & "$1" & "$2" & - "$3" + "$3" & + "}$N$N" & + "void PreMain() {$N" & + "\tvoid (*volatile inner)();$N" & + "\tsystemDatInit();$N" & + "\tinner = PreMainInner;$N" & + "$4" & + "\t(*inner)();$N" & + "}$N$N" MainProcs = "\tNimMain();$N" @@ -962,9 +973,6 @@ proc genMainProc(m: BModule) = MainProcsWithResult = MainProcs & "\treturn nim_program_result;$N" - # The use of a volatile function pointer to call NimMainInner - # prevents inlining of the NimMainInner function and dependent - # functions, which might otherwise merge their stack frames. NimMainBody = "N_CDECL(void, NimMainInner)(void) {$N" & "$1" & @@ -1047,8 +1055,8 @@ proc genMainProc(m: BModule) = platform.targetOS == osStandalone: "".toRope else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N") inc(m.labels) - appcg(m, m.s[cfsProcs], "void PreMain() {$N" & PreMainBody & "}$N$N", [ - mainDatInit, gBreakpoints, otherModsInit]) + appcg(m, m.s[cfsProcs], PreMainBody, [ + mainDatInit, gBreakpoints, otherModsInit, initStackBottomCall]) appcg(m, m.s[cfsProcs], nimMain, [mainModInit, initStackBottomCall, toRope(m.labels)]) if optNoMain notin gGlobalOptions: From bd32255f90f0789db10865ce5b5565c3af5b033b Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 14 Aug 2014 19:03:31 +0100 Subject: [PATCH 2/2] Fixes #1158. --- lib/pure/asyncdispatch.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index e1837b0ea7..5597acf6fa 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -27,7 +27,6 @@ export TPort, TSocketFlags ## **Note:** This module is still largely experimental. -# TODO: Discarded void PFutures need to be checked for exception. # TODO: ``except`` statement (without `try`) does not work. # TODO: Multiple exception names in a ``except`` don't work. # TODO: The effect system (raises: []) has trouble with my try transformation. @@ -1003,7 +1002,7 @@ proc processBody(node, retFutureSym: PNimrodNode, of nnkIdent: # await x result = newNimNode(nnkYieldStmt, node).add(node[1]) # -> yield x - of nnkCall: + of nnkCall, nnkCommand: # await foo(p, x) var futureValue: PNimrodNode result.createVar("future" & $node[1][0].toStrLit, node[1], futureValue, @@ -1020,7 +1019,7 @@ proc processBody(node, retFutureSym: PNimrodNode, of nnkVarSection, nnkLetSection: case node[0][2].kind of nnkCommand: - if node[0][2][0].ident == !"await": + if node[0][2][0].kind == nnkIdent and node[0][2][0].ident == !"await": # var x = await y var newVarSection = node # TODO: Should this use copyNimNode? result.createVar("future" & $node[0][0].ident, node[0][2][1],