From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 9DBF52CA791; Sat, 07 Nov 2026 19:53:27 +1100 (AEDT) Date: Sat, 07 Nov 2026 19:53:31 +1100 To: sup-commits@supmua.dev Subject: [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179404160709.118121.923149093806097164@bl2.djc.id.au> References: <179404160709.118121.923149093806097164@bl2.djc.id.au> Thread-Index: AQAAEjRWwScN9KkGSxule9y9SuyvqA== X-Git-Host: bl2.djc.id.au X-Git-Repo: ncursesw-ruby.git X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: d4b9570cdf7f06b6d3dfdf17c0c66c041284d4d6 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261107085327.9DBF52CA791@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch master: https://supmua.dev/git/ncursesw-ruby/commit/d4b9570cdf7f06b6d3dfdf17c0c66c041284d4d6.html commit d4b9570cdf7f06b6d3dfdf17c0c66c041284d4d6 Author: Dan Callaghan AuthorDate: Sat Nov 7 19:18:16 2026 +1100 clean up type confusion around clock_gettime() Although clock_gettime() uses struct timespec, select() still always uses struct timeval, and the code converts through double. So don't mix up the two structs. --- ncurses_wrap.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/ncurses_wrap.c b/ncurses_wrap.c index 88bc709..00d4111 100644 --- a/ncurses_wrap.c +++ b/ncurses_wrap.c @@ -857,13 +857,12 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f double starttime, nowtime, finishtime; double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0; fd_set in_fds; + struct timeval tv; #ifdef HAVE_CLOCK_GETTIME - struct timespec tv; - struct timeval ts; - clock_gettime (CLOCK_MONOTONIC, &tv); - starttime = tv.tv_sec + tv.tv_nsec * 1e-9; + struct timespec ts; + clock_gettime (CLOCK_MONOTONIC, &ts); + starttime = ts.tv_sec + ts.tv_nsec * 1e-9; #else - struct timeval tv; struct timezone tz = {0,0}; gettimeofday(&tv, &tz); starttime = tv.tv_sec + tv.tv_usec * 1e-6; @@ -876,8 +875,8 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f rb_fdset_t *rfds = NULL; #endif #ifdef HAVE_CLOCK_GETTIME - clock_gettime (CLOCK_MONOTONIC, &tv); - nowtime = tv.tv_sec + tv.tv_nsec * 1e-9; + clock_gettime (CLOCK_MONOTONIC, &ts); + nowtime = ts.tv_sec + ts.tv_nsec * 1e-9; #else gettimeofday(&tv, &tz); nowtime = tv.tv_sec + tv.tv_usec * 1e-6; @@ -888,16 +887,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f /* Check for terminal size change every resize_delay seconds */ if (resize_delay > delay) resize_delay = delay; tv.tv_sec = (time_t)resize_delay; -#ifdef HAVE_CLOCK_GETTIME - tv.tv_nsec = (unsigned)( (resize_delay - tv.tv_sec) * 1e9 ); -#else tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 ); -#endif - -#if HAVE_CLOCK_GETTIME - ts.tv_sec = tv.tv_sec; - ts.tv_usec = tv.tv_nsec * 1e-3; -#endif /* sleep on infd until input is available or tv reaches timeout */ FD_ZERO(&in_fds); @@ -907,20 +897,10 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f rfds = &fdsets[0]; rb_fd_init(rfds); rb_fd_copy(rfds, &in_fds, infd +1); - -#if HAVE_CLOCK_GETTIME - rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &ts); -#else rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv); -#endif rb_fd_term(rfds); - -#else -#if HAVE_CLOCK_GETTIME - rb_thread_select(infd + 1, &in_fds, NULL, NULL, &ts); #else rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv); -#endif #endif } wtimeout(c_win, windelay);