From 25a4026cdad0ab49499b9ffafc3e7dccfcd2d2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Mon, 30 Dec 2019 02:13:41 +0100 Subject: [PATCH] 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. (cherry picked from commit defaf3b5a55381f15da8e8e5c976cc18d9ce18ac) --- lib/system/ansi_c.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 16e7a14d60..7d6c0c7a17 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -142,8 +142,12 @@ proc c_realloc*(p: pointer, newsize: csize): pointer {. proc c_fwrite*(buf: pointer, size, n: csize, 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, s.len, f) + discard c_fflush(f) {.pop.}