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.

(cherry picked from commit defaf3b)
  • Loading branch information
stefantalpalaru authored and narimiran committed Jan 23, 2020
1 parent 2e9d595 commit 25a4026
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): 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.}

0 comments on commit 25a4026

Please sign in to comment.