hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit e9b63afe4adbc088b6c103548a50b10fdf20189f
parent 11ee81c199cd357cb8a5a6928d6ba5beddcbc9fa
Author: Alexey Yerin <yyp@disroot.org>
Date:   Sun,  1 May 2022 19:32:45 +0300

bufio: extend used buffer size when unreading

This caused parts of the buffer to be lost, most notably in
haredoc -Fhtml.

Fixes: https://todo.sr.ht/~sircmpwn/hare/673
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mbufio/buffered.ha | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/bufio/buffered.ha b/bufio/buffered.ha @@ -107,6 +107,7 @@ export fn unread(s: *bufstream, buf: []u8) void = { "Attempted to unread more data than buffer has available"); let sl = s.rbuffer[..s.ravail]; static insert(sl[0], buf...); + s.ravail += len(buf); }; // Unreads a rune; see [[unread]]. @@ -299,4 +300,12 @@ fn buffered_write(s: *io::stream, buf: const []u8) (size | io::error) = { for (let i = 0z; i < 8; i += 1) { assert(buf[i] == 0); }; + + let input: []u8 = [1, 2, 3, 4]; + let f = buffered(&fixed(input, io::mode::READ), rbuf, []); + + assert(io::read(&f, buf) as size == 4); + unread(&f, [1, 2, 3, 4]); + assert(io::read(&f, buf) as size == 4); + assert(io::read(&f, buf) is io::EOF); };