summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-15 07:00:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-15 07:00:59 -0700
commit6f346d97eb48d96e178aad0fdd163624410721c8 (patch)
tree6affa666e5729ab36b342da0b1a4baefb1487411
parent0bbc0fa33b249528270ff955b1d1d6dd494539ce (diff)
downloadtxr-6f346d97eb48d96e178aad0fdd163624410721c8.tar.gz
txr-6f346d97eb48d96e178aad0fdd163624410721c8.tar.bz2
txr-6f346d97eb48d96e178aad0fdd163624410721c8.zip
subprocesses: diagnose streams with no fileno.
* stream.c (fds_subst): Check that stream_fd returns a non-integer; if so, put out a more meaningful diagnostic, rather than allowing c_num to generate a "nil is not an integer" error. Also, let's incorporate the self string into the existing failed dup diagnostic.
-rw-r--r--stream.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/stream.c b/stream.c
index cc5a26f8..9d1d3a5f 100644
--- a/stream.c
+++ b/stream.c
@@ -4247,7 +4247,13 @@ static void fds_init(struct save_fds *fds)
static int fds_subst(val stream, int fd_std, val self)
{
- int fd_orig = c_num(stream_fd(stream), self);
+ val sfd = stream_fd(stream);
+ int fd_orig = if3(integerp(sfd), c_num(sfd, self), INT_MIN);
+
+
+ if (fd_orig == INT_MIN)
+ uw_throwf(file_error_s, lit("~a: (fileno ~s) is ~s, which is unusable"),
+ self, stream, sfd, nao);
if (fd_orig == fd_std)
return -1;
@@ -4260,8 +4266,8 @@ static int fds_subst(val stream, int fd_std, val self)
return fd_dup;
}
- uw_throwf(file_error_s, lit("failed to duplicate file descriptor: ~d/~s"),
- num(errno), errno_to_str(errno), nao);
+ uw_throwf(file_error_s, lit("~a: failed to duplicate file descriptor: ~d/~s"),
+ self, num(errno), errno_to_str(errno), nao);
}
}