From d735c447d35948ef6fda8270d1665cbd66c4636a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 1 Nov 2022 14:56:32 +0800 Subject: [PATCH] make `system/fatal` importable (#20719) --- lib/std/assertions.nim | 3 +-- lib/system.nim | 9 +++++++-- lib/system/fatal.nim | 19 +++++++------------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/std/assertions.nim b/lib/std/assertions.nim index 0bc4653f21..a39aee6c80 100644 --- a/lib/std/assertions.nim +++ b/lib/std/assertions.nim @@ -9,8 +9,7 @@ ## This module implements assertion handling. -when not declared(sysFatal): - include "system/fatal" +import system/fatal import std/private/miscdollars # --------------------------------------------------------------------------- diff --git a/lib/system.nim b/lib/system.nim index 95ba23a110..e84971aa2e 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1637,8 +1637,13 @@ when not defined(nimscript): ## for debug builds. Since it's usually used for debugging, this ## is proclaimed to have no IO effect! -when not declared(sysFatal): - include "system/fatal" + +when defined(nimHasExceptionsQuery): + const gotoBasedExceptions = compileOption("exceptions", "goto") +else: + const gotoBasedExceptions = false + +import system/fatal when not defined(nimscript): {.push stackTrace: off, profiler: off.} diff --git a/lib/system/fatal.nim b/lib/system/fatal.nim index c01787a326..6e2edf5734 100644 --- a/lib/system/fatal.nim +++ b/lib/system/fatal.nim @@ -9,27 +9,22 @@ {.push profiler: off.} -when defined(nimHasExceptionsQuery): - const gotoBasedExceptions = compileOption("exceptions", "goto") -else: - const gotoBasedExceptions = false - when hostOS == "standalone": include "$projectpath/panicoverride" - func sysFatal(exceptn: typedesc, message: string) {.inline.} = + func sysFatal*(exceptn: typedesc, message: string) {.inline.} = panic(message) - func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} = + func sysFatal*(exceptn: typedesc, message, arg: string) {.inline.} = rawoutput(message) panic(arg) elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript): - import ansi_c + import system/ansi_c func name(t: typedesc): string {.magic: "TypeTrait".} - func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = + func sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = when nimvm: # TODO when doAssertRaises works in CT, add a test for it raise (ref exceptn)(msg: message & arg) @@ -46,14 +41,14 @@ elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript): cstderr.rawWrite buf quit 1 - func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} = + func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} = sysFatal(exceptn, message, "") else: - func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} = + func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} = raise (ref exceptn)(msg: message) - func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = + func sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = raise (ref exceptn)(msg: message & arg) {.pop.}