summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-08-02 18:07:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-08-02 18:07:35 -0700
commit8917924aa32cdd300895e02ebc3472f273dfa411 (patch)
treeb9c2ed16fd030b3344e12e06076e85ca1c999b6b
parent905ef292831beda398fb9bc0e5aaf83878d348e0 (diff)
downloadtxr-8917924aa32cdd300895e02ebc3472f273dfa411.tar.gz
txr-8917924aa32cdd300895e02ebc3472f273dfa411.tar.bz2
txr-8917924aa32cdd300895e02ebc3472f273dfa411.zip
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.
-rw-r--r--stream.c6
-rw-r--r--strudel.c2
-rw-r--r--txr.16
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)