mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-09 21:28:13 +00:00
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:
@@ -7,6 +7,10 @@
|
||||
# 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.
|
||||
|
||||
import std/private/miscdollars
|
||||
@@ -26,7 +30,10 @@ proc `$`(info: InstantiationInfo): string =
|
||||
|
||||
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
||||
## 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: [].} =
|
||||
## Raises an `AssertionDefect` with `msg`, but this is hidden
|
||||
|
||||
@@ -1081,31 +1081,9 @@ proc align(address, alignment: int): int =
|
||||
else:
|
||||
result = (address + (alignment - 1)) and not (alignment - 1)
|
||||
|
||||
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.}
|
||||
include system/rawquits
|
||||
when defined(genode):
|
||||
export GenodeEnv
|
||||
|
||||
template sysAssert(cond: bool, msg: string) =
|
||||
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 """
|
||||
cmd: "nim $target $options --excessiveStackTrace:off $file"
|
||||
cmd: "nim $target $options -d:nimPreviewSlimSystem --excessiveStackTrace:off $file"
|
||||
output: '''true'''
|
||||
"""
|
||||
|
||||
import std/assertions
|
||||
const expected = """
|
||||
tassert_c.nim(35) tassert_c
|
||||
tassert_c.nim(34) foo
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
discard """
|
||||
errormsg: "unhandled exception: t9768.nim(24, 3) `a < 4` [AssertionDefect]"
|
||||
file: "std/assertions.nim"
|
||||
matrix: "-d:nimPreviewSlimSystem"
|
||||
nimout: '''
|
||||
stack trace: (most recent call last)
|
||||
t9768.nim(29, 33) main
|
||||
t9768.nim(24, 11) foo1
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
import std/assertions
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user