bufio: bclose flushes only, does not close the underlying (Hare flag::NONE)

This commit is contained in:
2026-06-15 02:09:59 +09:00
parent 9c10a731b0
commit a8b43b8f4b
2 changed files with 73 additions and 14 deletions

View File

@@ -46,8 +46,10 @@
// singletons (vtable_r / vtable_w / vtable_rw); ww's vtable always
// carries all three callbacks (a zero-length rbuf/wbuf degenerates the
// matching callback in-cb). Defer-handle (MANAGED_* ownership bits)
// also deferred — caller owns rbuf/wbuf/src; bclose flushes + forwards
// close but frees nothing. Both graduate with io fold-2 (#5).
// also deferred — caller owns rbuf/wbuf/src; bclose flushes only and
// neither frees nor closes (close-propagation rides #5
// MANAGED_HANDLE, ref/hare/bufio/stream.ha:194). Both graduate with io
// fold-2 (#5).
package bufio;
@@ -292,20 +294,15 @@ fn bwrite(s: io.stream, buf: []u8) (size | io.error) = {
return buf.len: size;
};
// bclose — flush pending wbuf, forward close to src via io.close.
// Caller-owned buffers/src are not freed (drew defer-handle deferral).
// bclose — flush pending wbuf only; the underlying src is NOT closed.
// Hare's close_buffered closes src solely under flag::MANAGED_HANDLE
// (ref/hare/bufio/stream.ha:194); init's default flag::NONE
// (stream.ha:73) flushes and leaves src to its owner. Close-propagation
// rides the io fold-2 MANAGED_HANDLE machinery (#5), per the ownership
// header (bufio.ww:46-50) — caller owns src, bclose frees/closes nothing.
fn bclose(s: io.stream) (void | io.error) = {
let b: *stream = s: *stream;
let fr: (void | io.error) = flush(b);
match (fr) {
case void => { };
case let e: io.error => return e;
};
let cr: (void | io.error) = io.close(b.src);
match (cr) {
case void => return void;
case let e: io.error => return e;
};
return flush(b);
};
// ---- scanner (read-ahead tokenizer over an io.stream src) ----------------