diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | lib.c | 6 | ||||
-rw-r--r-- | stream.c | 12 | ||||
-rw-r--r-- | txr.1 | 9 |
4 files changed, 28 insertions, 10 deletions
@@ -7,6 +7,17 @@ * tl.vim, txr.vim: Regenerated. +2014-12-25 Kaz Kylheku <kaz@kylheku.com> + + * lib.c (simple_lazy_stream_func): Bugfix: close the stream + if get_line returns nil. + + * stream.c (cat_get_line, cat_get_char, cat_get_byte): The catenated + stream read operations close an exhausted stream before popping + to the next one. + + * txr.1: Document closing behavior of catenated streams. + 2014-12-23 Kaz Kylheku <kaz@kylheku.com> * eval.c (ap_s, ret_s, aret_s): New symbol variables. @@ -5083,10 +5083,12 @@ toobig: static val simple_lazy_stream_func(val stream, val lcons) { - if (set(mkloc(lcons->lc.car, lcons), get_line(stream)) != nil) + if (set(mkloc(lcons->lc.car, lcons), get_line(stream)) != nil) { set(mkloc(lcons->lc.cdr, lcons), make_lazy_cons(lcons->lc.func)); - else + } else { + close_stream(stream, t); lcons->lc.cdr = nil; + } return nil; } @@ -2386,9 +2386,11 @@ static val cat_get_line(val stream) val streams = coerce(val, stream->co.handle); while (streams) { - val line = get_line(first(streams)); + val fs = first(streams); + val line = get_line(fs); if (line) return line; + close_stream(fs, t); if ((streams = rest(streams)) != nil) stream->co.handle = coerce(mem_t *, streams); } @@ -2401,9 +2403,11 @@ static val cat_get_char(val stream) val streams = coerce(val, stream->co.handle); while (streams) { - val ch = get_char(first(streams)); + val fs = first(streams); + val ch = get_char(fs); if (ch) return ch; + close_stream(fs, t); if ((streams = rest(streams)) != nil) stream->co.handle = coerce(mem_t *, streams); } @@ -2416,9 +2420,11 @@ static val cat_get_byte(val stream) val streams = coerce(val, stream->co.handle); while (streams) { - val byte = get_byte(first(streams)); + val fs = first(streams); + val byte = get_byte(fs); if (byte) return byte; + close_stream(fs, t); if ((streams = rest(streams)) != nil) stream->co.handle = coerce(mem_t *, streams); } @@ -22342,11 +22342,10 @@ or .code get-line operation on the head stream yields .codn nil , -and there are more lists in the stream, then the stream is removed from the -list, and the next stream, if any, becomes the head list. The operation is then -tried again. If any of these operations fail on the last list, it is not -removed from the list, so that a stream remains in place which can take -the +and there are more lists in the stream, then the stream is closed, removed from +the list, and the next stream, if any, becomes the head list. The operation is +then tried again. If any of these operations fail on the last list, it is not +removed from the list, so that a stream remains in place which can take the .code unget-char or .code unget-byte |