diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-04-25 10:43:42 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-04-25 10:43:42 -0700 |
commit | 1de059d0f51cd3aa003a9e0d1de4662a5f758c37 (patch) | |
tree | b888683dd7327f5a2f3afd5b5f14b6ad46ea1fca /stream.c | |
parent | 0b52768a15706b53e38890e1dc1ebc7f92e00166 (diff) | |
download | txr-1de059d0f51cd3aa003a9e0d1de4662a5f758c37.tar.gz txr-1de059d0f51cd3aa003a9e0d1de4662a5f758c37.tar.bz2 txr-1de059d0f51cd3aa003a9e0d1de4662a5f758c37.zip |
Reduce footprint of :fd property.
Querying the :fd stream property is equivalent to calling the
stream-fd function. Streams have a C virtual function get_fd,
so implementing :fd in their getprop functions is redundant
functionality. The stream-getprop function can test for
:fd and call stream-fd, so the stream implementations don't
have to deal with the :fd property.
Also, there are still places in the code base that are using
stream_getprop to get the file descriptor, instead of calling
stream_fd.
If we fix all this, then fd_k remains referenced only in
a very small number of places.
* socket.c (dgram_get_prop): Don't handle :fd any more.
* stream.c (unimpl_get_fd): Static function removed.
(fill_stream_ops): Default the get_fd function to null_get_fd
instead of unimpl_get_fd, so it doesn't throw.
Even a stdio stream don't throw; when the file is closed,
it returns nil.
(stdio_get_prop): Don't handle :fd any more.
(stream_get_prop): Handle :fd here. If the stream has a get_fd
function that isn't null_get_fd, then call it. Only if the
stream doesn't have a get_fd function, fall back on its
get_prop function.
* sysif.c (mkdir_wrap, poll_wrap, simulate_setuid_setgid):
Call stream_fd instead of stream_get_prop.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -217,11 +217,6 @@ static noreturn val unimpl_truncate(val stream, val len) unimpl(stream, lit("truncate-stream")); } -static noreturn val unimpl_get_fd(val stream) -{ - unimpl(stream, lit("fileno")); -} - static noreturn val unimpl_get_sock_family(val stream) { unimpl(stream, lit("sock-family")); @@ -421,7 +416,7 @@ void fill_stream_ops(struct strm_ops *ops) if (!ops->clear_error) ops->clear_error = null_clear_error; if (!ops->get_fd) - ops->get_fd = unimpl_get_fd; + ops->get_fd = null_get_fd; if (!ops->get_sock_family) ops->get_sock_family = unimpl_get_sock_family; if (!ops->get_sock_type) @@ -726,8 +721,6 @@ static val stdio_get_prop(val stream, val ind) return h->is_real_time ? t : nil; } else if (ind == name_k) { return h->descr; - } else if (ind == fd_k) { - return h->f ? num(fileno(h->f)) : nil; } else if (ind == byte_oriented_k) { return h->is_byte_oriented ? t : nil; } @@ -2896,6 +2889,10 @@ val stream_get_prop(val stream, val ind) val self = lit("stream-get-prop"); struct strm_ops *ops = coerce(struct strm_ops *, cobj_ops(self, stream, stream_s)); + + if (ind == fd_k && ops->get_fd != null_get_fd) + return ops->get_fd(stream); + return ops->get_prop(stream, ind); } |