diff options
-rw-r--r-- | stream.c | 6 | ||||
-rw-r--r-- | tests/018/close-delegate.expected | 3 | ||||
-rw-r--r-- | tests/018/close-delegate.tl | 20 | ||||
-rw-r--r-- | txr.1 | 2 |
4 files changed, 28 insertions, 3 deletions
@@ -119,7 +119,7 @@ static val shell, shell_arg; void strm_base_init(struct strm_base *s) { - static struct strm_base init = { indent_off, 60, 10, 0, 0, 0, 0, 0, nao, 0 }; + static struct strm_base init = { indent_off, 60, 10, 0, 0, 0, 0, 0, nil, 0 }; *s = init; } @@ -130,7 +130,7 @@ void strm_base_cleanup(struct strm_base *s) void strm_base_mark(struct strm_base *s) { - if (s->close_result != nao) + if (s->close_result) gc_mark(s->close_result); } @@ -2989,7 +2989,7 @@ val close_stream(val stream, val throw_on_error) cobj_handle(self, stream, stream_cls)); struct strm_ops *ops = coerce(struct strm_ops *, stream->co.ops); - if (s->close_result == nao) + if (!s->close_result) s->close_result = ops->close(stream, throw_on_error); return s->close_result; diff --git a/tests/018/close-delegate.expected b/tests/018/close-delegate.expected new file mode 100644 index 00000000..227f9f67 --- /dev/null +++ b/tests/018/close-delegate.expected @@ -0,0 +1,3 @@ +close called, count 2 +close called, count 1 +20 diff --git a/tests/018/close-delegate.tl b/tests/018/close-delegate.tl new file mode 100644 index 00000000..4cf1d650 --- /dev/null +++ b/tests/018/close-delegate.tl @@ -0,0 +1,20 @@ +(load "../common") + +(defstruct refcount-close stream-wrap + stream + (count 1) + + (:method close (me throw-on-error-p) + (put-line `close called, count @{me.count}`) + (when (plusp me.count) + (if (zerop (dec me.count)) + (close-stream me.stream throw-on-error-p))))) + +(flow + (with-stream (s (make-struct-delegate-stream + (new refcount-close + count 2 + stream (open-file *load-path*)))) + (get-lines s)) + len + prinl) @@ -62097,6 +62097,8 @@ instead of returning If .code close-stream is called in such a way that it returns a value, without throwing an exception, +and that value isn't +.codn nil , that value is retained. Additional calls to the function with the same .meta stream object return that same value without having any effect on the stream. |