diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-02-11 01:16:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 10:16:30 +0100 |
commit | 39ba502f8734b8f2cfda50841f5729356815c2fa (patch) | |
tree | 535d8df59e9b5b13256c75956d7ae646f3c043a4 /lib | |
parent | 1f7c907e7d81ae454739a2db753661505a5ed3d6 (diff) | |
download | Nim-39ba502f8734b8f2cfda50841f5729356815c2fa.tar.gz |
fix #9634 don't crash on execCmdEx/readLine when inside gdb/lldb (#13232)
* fix #9634 debugging a program using execCmdEx now works * only apply EINTR to c_gets for now This reverts commit c0f5305b5a0b46983dfd27e3d77ecbf4f8744dcc.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/io.nim | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/system/io.nim b/lib/system/io.nim index 4bbae98b7..7b9a893bb 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -145,6 +145,7 @@ proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".} when not defined(NimScript): var errno {.importc, header: "<errno.h>".}: cint ## error variable + EINTR {.importc: "EINTR", header: "<errno.h>".}: cint proc checkErr(f: File) = when not defined(NimScript): @@ -319,8 +320,20 @@ proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], # fgets doesn't append an \L for i in 0..<sp: line.string[pos+i] = '\L' - var fgetsSuccess = c_fgets(addr line.string[pos], sp.cint, f) != nil - if not fgetsSuccess: checkErr(f) + var fgetsSuccess: bool + while true: + # fixes #9634; this pattern may need to be abstracted as a template if reused; + # likely other io procs need this for correctness. + fgetsSuccess = c_fgets(addr line.string[pos], sp.cint, f) != nil + if fgetsSuccess: break + when not defined(NimScript): + if errno == EINTR: + errno = 0 + c_clearerr(f) + continue + checkErr(f) + break + let m = c_memchr(addr line.string[pos], '\L'.ord, cast[csize_t](sp)) if m != nil: # \l found: Could be our own or the one by fgets, in any case, we're done |