From ad4f45ca18f5804b58ff08dd8ecee67507b8d00a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 2 Aug 2021 18:07:35 -0700 Subject: streams: bad argument defaulting in close-stream. * stream.c (stdio_close, pipe_close): Fix throw_on_error argument not being defaulted correctly, so that errors are thrown even when the argument is omitted. * strudel.c (strudel_close): Here, we also must default the argument. The corresponding close method does not have an optional argument; it is mandatory. The documentation is bungled for it, though. * txr.1: Fix documentation of structure delegate streams with regard to the close method. It does not take offs and whence parametrs, but throw-on-error-p, which is mandatory. --- stream.c | 6 +++--- strudel.c | 2 +- txr.1 | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stream.c b/stream.c index 00e0228d..a1f5ead2 100644 --- a/stream.c +++ b/stream.c @@ -978,7 +978,7 @@ static val stdio_close(val stream, val throw_on_error) if (h->f != 0 && h->f != stdin && h->f != stdout && h->f != stderr) { int result = fclose(h->f); h->f = 0; - if (result == EOF && throw_on_error) { + if (result == EOF && default_null_arg(throw_on_error)) { h->err = num(errno); uw_throwf(file_error_s, lit("error closing ~s: ~d/~s"), stream, num(errno), errno_to_str(errno), nao); @@ -1378,7 +1378,7 @@ static val pipe_close(val stream, val throw_on_error) stream, num(errno), errno_to_str(errno), nao); } else { #if HAVE_SYS_WAIT - if (throw_on_error) { + if (default_null_arg(throw_on_error)) { if (WIFSIGNALED(status)) { int termsig = WTERMSIG(status); uw_throwf(process_error_s, lit("pipe ~s terminated by signal ~a"), @@ -1397,7 +1397,7 @@ static val pipe_close(val stream, val throw_on_error) return num(exitstatus); } #else - if (status != 0 && throw_on_error) + if (status != 0 && default_null_arg(throw_on_error)) uw_throwf(process_error_s, lit("closing pipe ~s failed"), stream, nao); #endif return status == 0 ? zero : nil; diff --git a/strudel.c b/strudel.c index e0866a98..50db20cb 100644 --- a/strudel.c +++ b/strudel.c @@ -145,7 +145,7 @@ static val strudel_close(val stream, val throw_on_error) struct strudel_base *sb = coerce(struct strudel_base *, stream->co.handle); val obj = sb->obj; val meth = slot(obj, close_s); - return funcall2(meth, obj, throw_on_error); + return funcall2(meth, obj, default_null_arg(throw_on_error)); } static val strudel_flush(val stream) diff --git a/txr.1 b/txr.1 index 62c791df..6bde1bbc 100644 --- a/txr.1 +++ b/txr.1 @@ -60159,7 +60159,7 @@ invocation. .coNP Method @ close .synb -.mets << stream .(close offs whence) +.mets << stream .(close throw-on-error-p) .syne .desc The @@ -60311,8 +60311,8 @@ stream I/O function. .mets \ \ \ \ (put-buf buf pos me.stream)) .mets \ \ (:method fill-buf (me buf pos) .mets \ \ \ \ (fill-buf buf pos me.stream)) -.mets \ \ (:method close (me) -.mets \ \ \ \ (close-stream me.stream)) +.mets \ \ (:method close (me throw-on-error) +.mets \ \ \ \ (close-stream me.stream throw-on-error)) .mets \ \ (:method flush (me) .mets \ \ \ \ (flush-stream me.stream)) .mets \ \ (:method seek (me offs whence) -- cgit v1.2.3