From 0a45facfe39ff943a0e290f4b6d5ac6481bb31f4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 15 Jun 2021 07:00:59 -0700 Subject: 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. --- stream.c | 12 +++++++++--- 1 file 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); } } -- cgit v1.2.3