From defaf3b5a55381f15da8e8e5c976cc18d9ce18ac Mon Sep 17 00:00:00 2001 From: Ștefan Talpalaru Date: Mon, 30 Dec 2019 02:13:41 +0100 Subject: c_fflush() the rawWrite() buffer (#12987) Stack traces on an unbuffered stderr get out of sync with line-buffered stdout - usually on Windows terminals or CI logs. This fixes it by calling C's fflush() on the output buffer in the procedure used for printing stack traces. --- lib/system/ansi_c.nim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/system') diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 79311a2f6..b9f719d9e 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -142,8 +142,12 @@ proc c_realloc*(p: pointer, newsize: csize_t): pointer {. proc c_fwrite*(buf: pointer, size, n: csize_t, f: CFilePtr): cint {. importc: "fwrite", header: "".} +proc c_fflush(f: CFilePtr): cint {. + importc: "fflush", header: "".} + proc rawWrite*(f: CFilePtr, s: cstring) {.compilerproc, nonReloadable, inline.} = # we cannot throw an exception here! discard c_fwrite(s, 1, cast[csize_t](s.len), f) + discard c_fflush(f) {.pop.} -- cgit 1.4.1-2-gfad0