fixes #21195; std/assertions continue to use sysFatal when nimPreviewSlimSystem is not defined (#21196)
* fixes #21195; `std/assertions` continue to use `sysFatal` * try includes * make `std/assertions` self-contained * fixes tests * fixes tests
This commit is contained in:
parent
705da9d452
commit
ebd1c678be
7 changed files with 63 additions and 30 deletions
|
|
@ -7,6 +7,10 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
when not defined(nimPreviewSlimSystem) and not declared(sysFatal):
|
||||||
|
include "system/rawquits"
|
||||||
|
include "system/fatal"
|
||||||
|
|
||||||
## This module implements assertion handling.
|
## This module implements assertion handling.
|
||||||
|
|
||||||
import std/private/miscdollars
|
import std/private/miscdollars
|
||||||
|
|
@ -26,7 +30,10 @@ proc `$`(info: InstantiationInfo): string =
|
||||||
|
|
||||||
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
||||||
## Raises an `AssertionDefect` with `msg`.
|
## Raises an `AssertionDefect` with `msg`.
|
||||||
raise newException(AssertionDefect, msg)
|
when defined(nimPreviewSlimSystem):
|
||||||
|
raise newException(AssertionDefect, msg)
|
||||||
|
else:
|
||||||
|
sysFatal(AssertionDefect, msg)
|
||||||
|
|
||||||
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||||
## Raises an `AssertionDefect` with `msg`, but this is hidden
|
## Raises an `AssertionDefect` with `msg`, but this is hidden
|
||||||
|
|
|
||||||
|
|
@ -1081,31 +1081,9 @@ proc align(address, alignment: int): int =
|
||||||
else:
|
else:
|
||||||
result = (address + (alignment - 1)) and not (alignment - 1)
|
result = (address + (alignment - 1)) and not (alignment - 1)
|
||||||
|
|
||||||
when defined(nimNoQuit):
|
include system/rawquits
|
||||||
proc rawQuit(errorcode: int = QuitSuccess) = discard "ignoring quit"
|
when defined(genode):
|
||||||
|
export GenodeEnv
|
||||||
elif defined(genode):
|
|
||||||
import genode/env
|
|
||||||
|
|
||||||
var systemEnv {.exportc: runtimeEnvSym.}: GenodeEnvPtr
|
|
||||||
|
|
||||||
type GenodeEnv* = GenodeEnvPtr
|
|
||||||
## Opaque type representing Genode environment.
|
|
||||||
|
|
||||||
proc rawQuit(env: GenodeEnv; errorcode: int) {.magic: "Exit", noreturn,
|
|
||||||
importcpp: "#->parent().exit(@); Genode::sleep_forever()", header: "<base/sleep.h>".}
|
|
||||||
|
|
||||||
proc rawQuit(errorcode: int = QuitSuccess) {.inline, noreturn.} =
|
|
||||||
systemEnv.rawQuit(errorcode)
|
|
||||||
|
|
||||||
|
|
||||||
elif defined(js) and defined(nodejs) and not defined(nimscript):
|
|
||||||
proc rawQuit(errorcode: int = QuitSuccess) {.magic: "Exit",
|
|
||||||
importc: "process.exit", noreturn.}
|
|
||||||
|
|
||||||
else:
|
|
||||||
proc rawQuit(errorcode: cint) {.
|
|
||||||
magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.}
|
|
||||||
|
|
||||||
template sysAssert(cond: bool, msg: string) =
|
template sysAssert(cond: bool, msg: string) =
|
||||||
when defined(useSysAssert):
|
when defined(useSysAssert):
|
||||||
|
|
|
||||||
27
lib/system/rawquits.nim
Normal file
27
lib/system/rawquits.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import system/ctypes
|
||||||
|
|
||||||
|
when defined(nimNoQuit):
|
||||||
|
proc rawQuit(errorcode: int = QuitSuccess) = discard "ignoring quit"
|
||||||
|
|
||||||
|
elif defined(genode):
|
||||||
|
import genode/env
|
||||||
|
|
||||||
|
var systemEnv {.exportc: runtimeEnvSym.}: GenodeEnvPtr
|
||||||
|
|
||||||
|
type GenodeEnv = GenodeEnvPtr
|
||||||
|
## Opaque type representing Genode environment.
|
||||||
|
|
||||||
|
proc rawQuit(env: GenodeEnv; errorcode: int) {.magic: "Exit", noreturn,
|
||||||
|
importcpp: "#->parent().exit(@); Genode::sleep_forever()", header: "<base/sleep.h>".}
|
||||||
|
|
||||||
|
proc rawQuit(errorcode: int = QuitSuccess) {.inline, noreturn.} =
|
||||||
|
systemEnv.rawQuit(errorcode)
|
||||||
|
|
||||||
|
|
||||||
|
elif defined(js) and defined(nodejs) and not defined(nimscript):
|
||||||
|
proc rawQuit(errorcode: int = QuitSuccess) {.magic: "Exit",
|
||||||
|
importc: "process.exit", noreturn.}
|
||||||
|
|
||||||
|
else:
|
||||||
|
proc rawQuit(errorcode: cint) {.
|
||||||
|
magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.}
|
||||||
15
tests/assert/panicoverride.nim
Normal file
15
tests/assert/panicoverride.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# panicoverride.nim
|
||||||
|
|
||||||
|
proc printf(fmt: cstring) {.varargs, importc, header:"stdio.h".}
|
||||||
|
proc exit(code: cint) {.importc, header:"stdlib.h".}
|
||||||
|
|
||||||
|
{.push stack_trace: off, profiler:off.}
|
||||||
|
|
||||||
|
proc rawoutput(s: cstring) =
|
||||||
|
printf("RAW: %s\n", s)
|
||||||
|
|
||||||
|
proc panic(s: cstring) {.noreturn.} =
|
||||||
|
printf("PANIC: %s\n", s)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
{.pop.}
|
||||||
6
tests/assert/t21195.nim
Normal file
6
tests/assert/t21195.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
discard """
|
||||||
|
matrix: "--verbosity:0 --os:standalone --mm:none"
|
||||||
|
"""
|
||||||
|
# bug #21195
|
||||||
|
var n = 11
|
||||||
|
assert(n == 12)
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim $target $options --excessiveStackTrace:off $file"
|
cmd: "nim $target $options -d:nimPreviewSlimSystem --excessiveStackTrace:off $file"
|
||||||
output: '''true'''
|
output: '''true'''
|
||||||
"""
|
"""
|
||||||
|
import std/assertions
|
||||||
const expected = """
|
const expected = """
|
||||||
tassert_c.nim(35) tassert_c
|
tassert_c.nim(35) tassert_c
|
||||||
tassert_c.nim(34) foo
|
tassert_c.nim(34) foo
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "unhandled exception: t9768.nim(24, 3) `a < 4` [AssertionDefect]"
|
errormsg: "unhandled exception: t9768.nim(24, 3) `a < 4` [AssertionDefect]"
|
||||||
file: "std/assertions.nim"
|
file: "std/assertions.nim"
|
||||||
|
matrix: "-d:nimPreviewSlimSystem"
|
||||||
nimout: '''
|
nimout: '''
|
||||||
stack trace: (most recent call last)
|
stack trace: (most recent call last)
|
||||||
t9768.nim(29, 33) main
|
t9768.nim(29, 33) main
|
||||||
t9768.nim(24, 11) foo1
|
t9768.nim(24, 11) foo1
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
import std/assertions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue