summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-12-25 11:43:16 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-12-25 11:43:16 -0800
commitfd4bdd5889162d26bf2f195224e6a3c675696f8e (patch)
treeabf3605e7eab57f9b0c059515cf4a57622c2a33a /stream.c
parent1f9ca760323c55d500876ec765001b43bbef8a53 (diff)
downloadtxr-fd4bdd5889162d26bf2f195224e6a3c675696f8e.tar.gz
txr-fd4bdd5889162d26bf2f195224e6a3c675696f8e.tar.bz2
txr-fd4bdd5889162d26bf2f195224e6a3c675696f8e.zip
* 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.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/stream.c b/stream.c
index c4632344..7945e43c 100644
--- a/stream.c
+++ b/stream.c
@@ -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);
}