This commit is contained in:
araq
2024-06-04 20:39:15 +02:00
parent 7906c05824
commit 4a6eea6894
2 changed files with 13 additions and 2 deletions

View File

@@ -1281,6 +1281,8 @@ proc genProcAux*(m: BModule, prc: PSym) =
if beforeRetNeeded in p.flags: generatedProc.add("{")
generatedProc.add(p.s(cpsInit))
generatedProc.add(p.s(cpsStmts))
if m.config.isDefined("nimUseCpuFlag"):
generatedProc.add("\tNIM_ERR_CLEAR();\n")
if beforeRetNeeded in p.flags: generatedProc.add("\t}BeforeRet_: ;\n")
if optStackTrace in prc.options: generatedProc.add(deinitFrame(p))
generatedProc.add(returnStmt)

View File

@@ -448,6 +448,9 @@ when gotoBasedExceptions:
## This proc must be called before `currException` is destroyed.
## It also must be called at the end of every thread to ensure no
## error is swallowed.
when defined(nimUseCpuFlag):
var nimInErrorMode = false
{.emit: "NIM_ERR_JUMP(Lerr_); goto Lend_; Lerr_: `nimInErrorMode` = NIM_TRUE; Lend_: ;".}
if nimInErrorMode and currException != nil:
reportUnhandledError(currException)
currException = nil
@@ -472,7 +475,10 @@ proc raiseExceptionAux(e: sink(ref Exception)) {.nodestroy.} =
elif quirkyExceptions or gotoBasedExceptions:
pushCurrentException(e)
when gotoBasedExceptions:
nimInErrorMode = true
when defined(nimUseCpuFlag):
{.emit: "NIM_ERR_SET();".}
else:
nimInErrorMode = true
else:
if excHandler != nil:
pushCurrentException(e)
@@ -512,7 +518,10 @@ proc reraiseException() {.compilerRtl.} =
sysFatal(ReraiseDefect, "no exception to reraise")
else:
when gotoBasedExceptions:
inc nimInErrorMode
when defined(nimUseCpuFlag):
{.emit: "NIM_ERR_SET();".}
else:
nimInErrorMode = true
else:
raiseExceptionAux(currException)