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 defaf3b5a5)
This commit is contained in:
Ștefan Talpalaru
2019-12-30 02:13:41 +01:00
committed by narimiran
parent 2e9d595f92
commit 25a4026cda

View File

@@ -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: "<stdio.h>".}
proc c_fflush(f: CFilePtr): cint {.
importc: "fflush", header: "<stdio.h>".}
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.}