commit e2337b266467074ad809c4a9af91100025f499ce
parent 74901a2641ab1a02bfafdcc461ebd4d5a3fe6b7f
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Wed, 1 May 2013 17:05:50 +0200
Conditionally use rb_thread_select on ruby 1.8.7
Diffstat:
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/extconf.rb b/extconf.rb
@@ -23,7 +23,6 @@
require "mkmf"
$CFLAGS += " -g -Wformat -Werror=format-security"
-$CXXFLAGS = $CFLAGS
have_header("unistd.h")
have_header("locale.h")
@@ -134,4 +133,11 @@ if have_header("menu.h")
have_library("menu", "new_menu")
end
+if (have_func ("rb_thread_fd_select"))
+ $CFLAGS += " -DHAVE_RB_THREAD_FD_SELECT"
+end
+
+$CXXFLAGS = $CFLAGS
+
create_makefile('ncursesw_bin')
+
diff --git a/ncurses_wrap.c b/ncurses_wrap.c
@@ -836,8 +836,10 @@ static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) {
c_win->_delay = 0;
#endif
while (doupdate() /* detects resize */, (result = wgetch(c_win)) == ERR) {
+#ifdef HAVE_RB_THREAD_FD_SELECT
rb_fdset_t fdsets[3];
rb_fdset_t *rfds = NULL;
+#endif
gettimeofday(&tv, &tz);
nowtime = tv.tv_sec + tv.tv_usec * 1e-6;
delay = finishtime - nowtime;
@@ -851,13 +853,16 @@ static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) {
/* sleep on infd until input is available or tv reaches timeout */
FD_ZERO(&in_fds);
FD_SET(infd, &in_fds);
- //rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv);
+#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);
+#else
+ rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
+#endif
}
#ifdef NCURSES_VERSION
c_win->_delay = windelay;