From 41c97e4b70d8d3b67f9080939790c6b9a64a7e74 Mon Sep 17 00:00:00 2001 From: ktamp Date: Fri, 26 Jun 2020 00:31:06 +0300 Subject: readLine: Fix issues with --gc:arc **--gc:arc** defines **nimv2**. This changes the definition of **WideCStringObj**. Also an empty string should be returned in case of EOF. --- lib/system/io.nim | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib/system') diff --git a/lib/system/io.nim b/lib/system/io.nim index b550b6b7b..9f12a1767 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -354,8 +354,8 @@ proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], when defined(windows) and not defined(useWinAnsi): proc readConsole(hConsoleInput: FileHandle, lpBuffer: pointer, - nNumberOfCharsToRead: uint32, - lpNumberOfCharsRead: ptr uint32, + nNumberOfCharsToRead: int32, + lpNumberOfCharsRead: ptr int32, pInputControl: pointer): int32 {. importc: "ReadConsoleW", stdcall, dynlib: "kernel32".} @@ -383,7 +383,7 @@ proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], # this implies the file is open if f.isatty: const numberOfCharsToRead = 2048 - var numberOfCharsRead = 0'u32 + var numberOfCharsRead = 0'i32 var buffer = newWideCString("", numberOfCharsToRead) if readConsole(getOsFileHandle(f), addr(buffer[0]), numberOfCharsToRead, addr(numberOfCharsRead), nil) == 0: @@ -393,20 +393,25 @@ proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], if formatMessageW(0x00000100 or 0x00001000 or 0x00000200, nil, error, 0, addr(msgbuf), 0, nil) != 0'i32: errorMsg = $msgbuf - if msgbuf != nil: localFree(cast[pointer](msgbuf)) + if msgbuf != nil: + localFree(cast[pointer](msgbuf)) raiseEIO("error: " & $error & " `" & errorMsg & "`") # input always ends with "\r\n" numberOfCharsRead -= 2 # handle Ctrl+Z as EOF - for i in 0'u32..