Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime()
Date: Sat, 07 Nov 2026 19:53:31 +1100	[thread overview]
Message-ID: <20261107085327.9DBF52CA791@bl2.djc.id.au> (raw)
In-Reply-To: <179404160709.118121.923149093806097164@bl2.djc.id.au>

New commit on branch master:
https://supmua.dev/git/ncursesw-ruby/commit/d4b9570cdf7f06b6d3dfdf17c0c66c041284d4d6.html

commit d4b9570cdf7f06b6d3dfdf17c0c66c041284d4d6
Author: Dan Callaghan <djc@djc.id.au>
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);

  parent reply	other threads:[~2026-11-07  8:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 02/06: handle NULL for " Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 03/06: fix leaked rb_fdset in every iteration of getch() Dan Callaghan
2026-11-07  8:53 ` Dan Callaghan [this message]
2026-11-07  8:53 ` [ncursesw-ruby.git] 05/06: simplify usage of rb_fdset_t Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 06/06: return ERR from wgetch() immediately on EOF Dan Callaghan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261107085327.9DBF52CA791@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox