Skip to content

Commit

Permalink
c_fflush() the rawWrite() buffer (#12987)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stefantalpalaru authored and Clyybber committed Dec 30, 2019
1 parent 8d1a7db commit defaf3b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/system/ansi_c.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}

0 comments on commit defaf3b

Please sign in to comment.