diff options
-rw-r--r-- | lib/system/dyncalls.nim | 7 | ||||
-rw-r--r-- | lib/system/excpt.nim | 9 | ||||
-rw-r--r-- | tests/exception/t9657.nim | 6 |
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/system/dyncalls.nim b/lib/system/dyncalls.nim index d6c361b2c..70bdc429b 100644 --- a/lib/system/dyncalls.nim +++ b/lib/system/dyncalls.nim @@ -17,13 +17,6 @@ const NilLibHandle: LibHandle = nil -proc c_fwrite(buf: pointer, size, n: csize, f: File): cint {. - importc: "fwrite", header: "<stdio.h>".} - -proc rawWrite(f: File, s: string|cstring) = - # we cannot throw an exception here! - discard c_fwrite(cstring(s), 1, s.len, f) - proc nimLoadLibraryError(path: string) = # carefully written to avoid memory allocation: stderr.rawWrite("could not load: ") diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 778137668..a6da8f5a3 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -17,8 +17,15 @@ var ## instead of stdmsg.write when printing stacktrace. ## Unstable API. +proc c_fwrite(buf: pointer, size, n: csize, f: File): cint {. + importc: "fwrite", header: "<stdio.h>".} + +proc rawWrite(f: File, s: string|cstring) = + # we cannot throw an exception here! + discard c_fwrite(cstring(s), 1, s.len, f) + when not defined(windows) or not defined(guiapp): - proc writeToStdErr(msg: cstring) = write(stdmsg, msg) + proc writeToStdErr(msg: cstring) = rawWrite(stdmsg, msg) else: proc MessageBoxA(hWnd: cint, lpText, lpCaption: cstring, uType: int): int32 {. diff --git a/tests/exception/t9657.nim b/tests/exception/t9657.nim new file mode 100644 index 000000000..5d5164f4f --- /dev/null +++ b/tests/exception/t9657.nim @@ -0,0 +1,6 @@ +discard """ + action: run + exitcode: 1 +""" +close stdmsg +writeLine stdmsg, "exception!" |