add io.readChars overload (simpler, less error prone) #16044
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
add io.readChars overload (simpler, less error prone)
see tests tests/stdlib/tio.nim; I'm noticing that io.nim isn't tested (at least lots of procs aren't), so tio.nim is a start
removed
which doesn't make sense to me; it's impossible to not have
a
pre-allocated unless I'm missing somethingreadChars
overload since the new one is simpler, less error prone (impossible to misuse the way the other one was, as evidenced by lack ofraiseEIO("buffer overflow: (start+len) > length of openarray buffer")
readChars(toOpenArray(buf, start, len-1)
, making the old one superfluous (and 99% of the time you'd simply usereadChars(f, buf)
withouttoOpenArray
anyways)note regarding
since
I didn't use
since: (1,5,1)
for simplicity, and so that stdlib (lib/std/sha1.nim and ./lib/wrappers/openssl.nim) can use the newreadChars
proc, simplifying code, promoting the new preferred one, and avoiding the warning.as usual, if/when #11865 (recently rebased to avoid conflict bitrot) is merged I'd be able to use
since: (1,5,1)
forreadChars
and stdlib code could use:note regarding test
I've used
defer
, but it's a test, not compiler code. See also #16048