From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: * X-Spam-ASN: AS60068 185.152.64.0/23 X-Spam-Status: No, score=1.0 required=3.0 tests=AWL,BAYES_00,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (tor-exit-node.1.justaguy.be [185.152.65.180]) by dcvr.yhbt.net (Postfix) with ESMTP id 5C3731F42B for ; Sun, 29 Apr 2018 03:50:13 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 1/2] thread.c (timeout_prepare): common function Date: Sun, 29 Apr 2018 03:50:06 +0000 Message-Id: <20180429035007.6499-2-e@80x24.org> In-Reply-To: <20180429035007.6499-1-e@80x24.org> References: <20180429035007.6499-1-e@80x24.org> List-Id: I can't seem to reproduce the maybe-uninitialized warning on gcc 7 or 8 on Debian sid (7.3.0-16 / 8-20180425-1 r259628), so the guard from r62305 is dropped. * thread.c (timeout_prepare): hoist out from do_select (do_select): ditto (rb_wait_for_single_fd): use timeout_prepare --- thread.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/thread.c b/thread.c index 881a066a92..65844f5442 100644 --- a/thread.c +++ b/thread.c @@ -232,6 +232,21 @@ timeval_for(struct timeval *tv, const struct timespec *ts) return 0; } +static void +timeout_prepare(struct timespec **tsp, + struct timespec *ts, struct timespec *end, + const struct timeval *timeout) +{ + if (timeout) { + getclockofday(end); + timespec_add(end, timespec_for(ts, timeout)); + *tsp = ts; + } + else { + *tsp = 0; + } +} + #if THREAD_DEBUG #ifdef HAVE_VA_ARGS_MACRO void rb_thread_debug(const char *file, int line, const char *fmt, ...); @@ -3808,27 +3823,16 @@ do_select(int n, rb_fdset_t *const readfds, rb_fdset_t *const writefds, rb_fdset_t MAYBE_UNUSED(orig_read); rb_fdset_t MAYBE_UNUSED(orig_write); rb_fdset_t MAYBE_UNUSED(orig_except); - struct timespec end; - struct timespec *tsp = 0; - struct timespec ts -#if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8) - = {0, 0} -#endif - ; + struct timespec ts, end, *tsp; rb_thread_t *th = GET_THREAD(); + timeout_prepare(&tsp, &ts, &end, timeout); #define do_select_update() \ (restore_fdset(readfds, &orig_read), \ restore_fdset(writefds, &orig_write), \ restore_fdset(exceptfds, &orig_except), \ update_timespec(tsp, &end)) - if (timeout) { - getclockofday(&end); - timespec_add(&end, timespec_for(&ts, timeout)); - tsp = &ts; - } - #define fd_init_copy(f) \ (f##fds) ? rb_fd_init_copy(&orig_##f, f##fds) : rb_fd_no_init(&orig_##f) fd_init_copy(read); @@ -3959,17 +3963,10 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout) { struct pollfd fds; int result = 0, lerrno; - struct timespec ts; - struct timespec end; - struct timespec *tsp = 0; + struct timespec ts, end, *tsp; rb_thread_t *th = GET_THREAD(); - if (timeout) { - getclockofday(&end); - timespec_add(&end, timespec_for(&ts, timeout)); - tsp = &ts; - } - + timeout_prepare(&tsp, &ts, &end, timeout); fds.fd = fd; fds.events = (short)events; -- EW