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] 06/06: return ERR from wgetch() immediately on EOF
Date: Sat, 07 Nov 2026 19:53:33 +1100	[thread overview]
Message-ID: <20261107085327.D39242CA795@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/f189aee4473e2253a03cb55364d13cfc4a72e5c6.html

commit f189aee4473e2253a03cb55364d13cfc4a72e5c6
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 7 19:36:29 2026 +1100

    return ERR from wgetch() immediately on EOF
    
    If the input reaches EOF, the file descriptor will be indicated as ready
    by select() but ncurses wgetch() will return ERR. Don't busy-loop in
    this case, just return the ERR straight away.
---
 ncurses_wrap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ncurses_wrap.c b/ncurses_wrap.c
index 967f2d2..04efd1e 100644
--- a/ncurses_wrap.c
+++ b/ncurses_wrap.c
@@ -861,6 +861,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
 #else
     fd_set in_fds;
 #endif
+    bool ready = false;
     struct timeval tv;
 #ifdef HAVE_CLOCK_GETTIME
     struct timespec ts;
@@ -873,7 +874,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
 #endif
     finishtime = starttime + delay;
     wtimeout(c_win, 0);
-    while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) {
+    while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR && !ready) {
 #ifdef HAVE_CLOCK_GETTIME
       clock_gettime (CLOCK_MONOTONIC, &ts);
       nowtime = ts.tv_sec + ts.tv_nsec * 1e-9;
@@ -894,11 +895,13 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
       rb_fd_init(&in_fds);
       rb_fd_set(infd, &in_fds);
       rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv);
+      ready = rb_fd_isset(infd, &in_fds);
       rb_fd_term(&in_fds);
 #else
       FD_ZERO(&in_fds);
       FD_SET(infd, &in_fds);
       rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
+      ready = FD_ISSET(infd, &in_fds);
 #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 ` [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime() Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 05/06: simplify usage of rb_fdset_t Dan Callaghan
2026-11-07  8:53 ` Dan Callaghan [this message]

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.D39242CA795@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