From b5730ec01f02e542eb06161430aa5a7c2ede775f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 5 Sep 2018 18:05:55 +0200 Subject: system.nim: fix doc comment for 'once' --- lib/system.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/system.nim') diff --git a/lib/system.nim b/lib/system.nim index a7e215168..2e5d5ae19 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -4127,13 +4127,13 @@ template once*(body: untyped): untyped = ## re-executed on each module reload. ## ## .. code-block:: nim - ## proc draw(t: Triangle) = - ## once: - ## graphicsInit() ## - ## line(t.p1, t.p2) - ## line(t.p2, t.p3) - ## line(t.p3, t.p1) + ## proc draw(t: Triangle) = + ## once: + ## graphicsInit() + ## line(t.p1, t.p2) + ## line(t.p2, t.p3) + ## line(t.p3, t.p1) ## var alreadyExecuted {.global.} = false if not alreadyExecuted: -- cgit 1.4.1-2-gfad0 From 4ab99537875a763e0540fbbe48d69cad454ca792 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 14 Sep 2018 11:40:43 +0200 Subject: fixes #8961 --- lib/system.nim | 4 ++-- lib/system/sysio.nim | 4 ++-- tests/stdlib/tio.nim | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/system.nim') diff --git a/lib/system.nim b/lib/system.nim index 2e5d5ae19..8654f12a1 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3127,8 +3127,8 @@ when not defined(JS): #and not defined(nimscript): proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], benign.} - ## reads a line of text from the file `f` into `line`. `line` must not be - ## ``nil``! May throw an IO exception. + ## reads a line of text from the file `f` into `line`. May throw an IO + ## exception. ## A line of text may be delimited by ``LF`` or ``CRLF``. The newline ## character(s) are not part of the returned string. Returns ``false`` ## if the end of the file has been reached, ``true`` otherwise. If diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 40bbf97dc..df13ab628 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -161,7 +161,7 @@ proc readLine(f: File, line: var TaintedString): bool = var last = cast[ByteAddress](m) - cast[ByteAddress](addr line.string[0]) if last > 0 and line.string[last-1] == '\c': line.string.setLen(last-1) - return fgetsSuccess + return last > 1 or fgetsSuccess # We have to distinguish between two possible cases: # \0\l\0 => line ending in a null character. # \0\l\l => last line without newline, null was put there by fgets. @@ -169,7 +169,7 @@ proc readLine(f: File, line: var TaintedString): bool = if last < pos + sp - 1 and line.string[last+1] != '\0': dec last line.string.setLen(last) - return fgetsSuccess + return last > 0 or fgetsSuccess else: # fgets will have inserted a null byte at the end of the string. dec sp diff --git a/tests/stdlib/tio.nim b/tests/stdlib/tio.nim index 28e1881e8..b1057dee2 100644 --- a/tests/stdlib/tio.nim +++ b/tests/stdlib/tio.nim @@ -1,9 +1,12 @@ discard """ output: '''9 -b = false +b = true 123456789 Second readLine raised an exception 123456789 +1 +2aaaaaaaa +3bbbbbbb ''' """ # bug #5349 @@ -38,3 +41,9 @@ echo line f.close() removeFile(fn) + +# bug #8961 +writeFile("test.txt", "1\C\L2aaaaaaaa\C\L3bbbbbbb") + +for line in lines("test.txt"): + echo line -- cgit 1.4.1-2-gfad0 From a34184bf88cc451f44c65f8e9afd6332080217ad Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 15 Sep 2018 00:23:27 +0200 Subject: documents system.cmp's platform specific behaviour; fixes #8930 --- lib/system.nim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/system.nim') diff --git a/lib/system.nim b/lib/system.nim index ef6138ad1..353500a4a 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1237,6 +1237,8 @@ proc cmp*[T](x, y: T): int {.procvar.} = proc cmp*(x, y: string): int {.noSideEffect, procvar.} ## Compare proc for strings. More efficient than the generic version. + ## **Note**: The precise result values depend on the used C runtime library and + ## can differ between operating systems! proc `@`* [IDX, T](a: array[IDX, T]): seq[T] {. magic: "ArrToSeq", nosideeffect.} -- cgit 1.4.1-2-gfad0