Attempt to finish off araq cpp exceptions (#13695)
* config update * disable a questionable test * remove c++ exception handling IDs, new impl doesn't require it anymore * C++ based exceptions finally work * fixes bootstrapping problem in C++ mode * teach GCC it's 2020 now * more bugfixes for C++ based exception handling * apply cooldome's patch * another attempt to enable C++11 * bug fix Co-authored-by: Araq <rumpf_a@web.de> Co-authored-by: cooldome <ariabushenko@bk.ru>
This commit is contained in:
parent
034dad8e32
commit
b3176b8817
12 changed files with 233 additions and 74 deletions
|
|
@ -33,12 +33,6 @@ type
|
|||
trace: string
|
||||
else:
|
||||
trace: seq[StackTraceEntry]
|
||||
when defined(nimBoostrapCsources0_19_0):
|
||||
# see #10315, bootstrap with `nim cpp` from csources gave error:
|
||||
# error: no member named 'raise_id' in 'Exception'
|
||||
raise_id: uint # set when exception is raised
|
||||
else:
|
||||
raiseId: uint # set when exception is raised
|
||||
up: ref Exception # used for stacking exceptions. Not exported!
|
||||
|
||||
Defect* = object of Exception ## \
|
||||
|
|
|
|||
|
|
@ -61,10 +61,6 @@ var
|
|||
currException {.threadvar.}: ref Exception
|
||||
gcFramePtr {.threadvar.}: GcFrame
|
||||
|
||||
when defined(cpp) and not defined(noCppExceptions) and not gotoBasedExceptions:
|
||||
var
|
||||
raiseCounter {.threadvar.}: uint
|
||||
|
||||
type
|
||||
FrameState = tuple[gcFramePtr: GcFrame, framePtr: PFrame,
|
||||
excHandler: PSafePoint, currException: ref Exception]
|
||||
|
|
@ -123,19 +119,7 @@ proc popCurrentException {.compilerRtl, inl.} =
|
|||
#showErrorMessage "B"
|
||||
|
||||
proc popCurrentExceptionEx(id: uint) {.compilerRtl.} =
|
||||
# in cpp backend exceptions can pop-up in the different order they were raised, example #5628
|
||||
if currException.raiseId == id:
|
||||
currException = currException.up
|
||||
else:
|
||||
var cur = currException.up
|
||||
var prev = currException
|
||||
while cur != nil and cur.raiseId != id:
|
||||
prev = cur
|
||||
cur = cur.up
|
||||
if cur == nil:
|
||||
showErrorMessage("popCurrentExceptionEx() exception was not found in the exception stack. Aborting...")
|
||||
quit(1)
|
||||
prev.up = cur.up
|
||||
discard "only for bootstrapping compatbility"
|
||||
|
||||
proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
|
||||
currException = e
|
||||
|
|
@ -444,11 +428,7 @@ proc raiseExceptionAux(e: sink(ref Exception)) {.nodestroy.} =
|
|||
{.emit: "throw;".}
|
||||
else:
|
||||
pushCurrentException(e)
|
||||
raiseCounter.inc
|
||||
if raiseCounter == 0:
|
||||
raiseCounter.inc # skip zero at overflow
|
||||
e.raiseId = raiseCounter
|
||||
{.emit: "`e`->raise();".}
|
||||
{.emit: "throw e;".}
|
||||
elif defined(nimQuirky) or gotoBasedExceptions:
|
||||
# XXX This check should likely also be done in the setjmp case below.
|
||||
if e != currException:
|
||||
|
|
@ -562,9 +542,9 @@ when defined(cpp) and appType != "lib" and not gotoBasedExceptions and
|
|||
|
||||
var msg = "Unknown error in unexpected exception handler"
|
||||
try:
|
||||
{.emit"#if !defined(_MSC_VER) || (_MSC_VER >= 1923)".}
|
||||
{.emit: "#if !defined(_MSC_VER) || (_MSC_VER >= 1923)".}
|
||||
raise
|
||||
{.emit"#endif".}
|
||||
{.emit: "#endif".}
|
||||
except Exception:
|
||||
msg = currException.getStackTrace() & "Error: unhandled exception: " &
|
||||
currException.msg & " [" & $currException.name & "]"
|
||||
|
|
@ -573,9 +553,9 @@ when defined(cpp) and appType != "lib" and not gotoBasedExceptions and
|
|||
except:
|
||||
msg = "Error: unhandled unknown cpp exception"
|
||||
|
||||
{.emit"#if defined(_MSC_VER) && (_MSC_VER < 1923)".}
|
||||
{.emit: "#if defined(_MSC_VER) && (_MSC_VER < 1923)".}
|
||||
msg = "Error: unhandled unknown cpp exception"
|
||||
{.emit"#endif".}
|
||||
{.emit: "#endif".}
|
||||
|
||||
when defined(genode):
|
||||
# stderr not available by default, use the LOG session
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue