diff options
author | Ștefan Talpalaru <stefantalpalaru@yahoo.com> | 2019-12-30 02:13:41 +0100 |
---|---|---|
committer | Clyybber <darkmine956@gmail.com> | 2019-12-30 02:13:41 +0100 |
commit | defaf3b5a55381f15da8e8e5c976cc18d9ce18ac (patch) | |
tree | f13768f9f92644a25e025cbfdc827282bf54445d /lib/system | |
parent | 8d1a7db6ea7cd4e8d9e2b38874477c12b99ffcd7 (diff) | |
download | Nim-defaf3b5a55381f15da8e8e5c976cc18d9ce18ac.tar.gz |
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.
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/ansi_c.nim | 4 |
1 files changed, 4 insertions, 0 deletions
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: "<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, cast[csize_t](s.len), f) + discard c_fflush(f) {.pop.} |