Skip to content

Commit

Permalink
fixes nim-lang#13013, reverts previous changes to readLines() (nim-la…
Browse files Browse the repository at this point in the history
…ng#13036) [backport]

* Revert "remove default argument for readLines (nim-lang#12807) [backport]"

This reverts commit c949b81.
  • Loading branch information
cooldome authored and Araq committed Jan 5, 2020
1 parent 9474a81 commit a3df1b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/vmops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ proc registerAdditionalOps*(c: PCtx) =
wrap1s(fileExists, osop)
wrapDangerous(writeFile, ioop)
wrap1s(readFile, ioop)
wrap2si(staticReadLines, ioop)
wrap2si(readLines, ioop)
systemop getCurrentExceptionMsg
systemop getCurrentException
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
Expand Down
8 changes: 5 additions & 3 deletions lib/system/io.nim
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,10 @@ proc writeFile*(filename: string, content: openArray[byte]) {.since: (1, 1).} =
else:
raise newException(IOError, "cannot open: " & filename)

proc staticReadLines*(filename: string, n: Natural): seq[TaintedString] =
## Compile time read `n` lines from the file named `filename`. Raises an IO exception
proc readLines*(filename: string, n: Natural): seq[TaintedString] =
## read `n` lines from the file named `filename`. Raises an IO exception
## in case of an error. Raises EOF if file does not contain at least `n` lines.
## A line of text may be delimited by ``LF`` or ``CRLF``.
## Available at compile time. A line of text may be delimited by ``LF`` or ``CRLF``.
## The newline character(s) are not part of the returned strings.
var f: File
if open(f, filename):
Expand All @@ -713,6 +713,8 @@ proc staticReadLines*(filename: string, n: Natural): seq[TaintedString] =
else:
sysFatal(IOError, "cannot open: " & filename)

proc readLines*(filename: string): seq[TaintedString] {.deprecated: "use readLines with two arguments".} =
readLines(filename, 1)

iterator lines*(filename: string): TaintedString {.tags: [ReadIOEffect].} =
## Iterates over any line in the file named `filename`.
Expand Down
2 changes: 1 addition & 1 deletion tests/vm/tfile_rw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static:
writeFile(filename, mytext)
const myfile_str = staticRead(filename)
const myfile_str2 = readFile(filename)
const myfile_str_seq = staticReadLines(filename, 3)
const myfile_str_seq = readLines(filename, 3)

static:
doAssert myfile_str == mytext
Expand Down

0 comments on commit a3df1b5

Please sign in to comment.