From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id BBAEB2CA793; Sat, 07 Nov 2026 19:53:27 +1100 (AEDT) Date: Sat, 07 Nov 2026 19:53:32 +1100 To: sup-commits@supmua.dev Subject: [ncursesw-ruby.git] 05/06: simplify usage of rb_fdset_t 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: f341b43e7324884400c69329e11f6cd234cbc388 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261107085327.BBAEB2CA793@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch master: https://supmua.dev/git/ncursesw-ruby/commit/f341b43e7324884400c69329e11f6cd234cbc388.html commit f341b43e7324884400c69329e11f6cd234cbc388 Author: Dan Callaghan AuthorDate: Sat Nov 7 19:31:23 2026 +1100 simplify usage of rb_fdset_t No need to allocate three of them and then go through a pointer. Copying from an old-fashioned fd_set also defeats the purpose of the Ruby wrapper, which is to handle fds larger than 1024. --- ncurses_wrap.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ncurses_wrap.c b/ncurses_wrap.c index 00d4111..967f2d2 100644 --- a/ncurses_wrap.c +++ b/ncurses_wrap.c @@ -856,7 +856,11 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f int result; double starttime, nowtime, finishtime; double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0; +#ifdef HAVE_RB_THREAD_FD_SELECT + rb_fdset_t in_fds; +#else fd_set in_fds; +#endif struct timeval tv; #ifdef HAVE_CLOCK_GETTIME struct timespec ts; @@ -870,10 +874,6 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f finishtime = starttime + delay; wtimeout(c_win, 0); while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) { -#ifdef HAVE_RB_THREAD_FD_SELECT - rb_fdset_t fdsets[3]; - rb_fdset_t *rfds = NULL; -#endif #ifdef HAVE_CLOCK_GETTIME clock_gettime (CLOCK_MONOTONIC, &ts); nowtime = ts.tv_sec + ts.tv_nsec * 1e-9; @@ -890,16 +890,14 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 ); /* sleep on infd until input is available or tv reaches timeout */ - FD_ZERO(&in_fds); - FD_SET(infd, &in_fds); - #ifdef HAVE_RB_THREAD_FD_SELECT - rfds = &fdsets[0]; - rb_fd_init(rfds); - rb_fd_copy(rfds, &in_fds, infd +1); - rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv); - rb_fd_term(rfds); + rb_fd_init(&in_fds); + rb_fd_set(infd, &in_fds); + rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv); + 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); #endif }