forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: revamp file IO, this time Windows compatible (leanprover#4950)
This implements a naive version of `getline` because Windows does not have `getline`. Given the fact that `FILE` has buffered IO, calling `fgetc` in a loop is not as big of a performance hazard as it might seem at first glance. The proper solution to this would of course be to have our own buffered IO so we are fully in charge of the buffer. In this situation we could check the entire buffer for a newline at once instead of char by char. However that is not going to happen for the near future so I propose we stay with this implementation. If reading individual lines of a file does truly end up being the performance bottle neck we have already won^^.
- Loading branch information
Showing
5 changed files
with
80 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def test : IO Unit := do | ||
let tmpFile := "3546.tmp" | ||
let firstLine := "foo\u0000bar\n" | ||
let content := firstLine ++ "hello world\nbye" | ||
IO.FS.writeFile tmpFile content | ||
let handle ← IO.FS.Handle.mk tmpFile .read | ||
let firstReadLine ← handle.getLine | ||
let cond := firstLine == firstReadLine && firstReadLine.length == 8 -- paranoid | ||
IO.println cond | ||
IO.FS.removeFile tmpFile | ||
|
||
/-- info: true -/ | ||
#guard_msgs in | ||
#eval test |