From: Brent Roman Date: 2007-10-09T07:15:07+09:00 Subject: [PATCH] to let Ruby 1.9 to process signals while blocked in ext/readline This is a multi-part message in MIME format. --------------040802060002000004020900 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Under Linux (and probably other Unix platforms), Ruby 1.9 appears to block signals (like SIGTERM and SIGINT) while a thread is awating input in Readline.readline. To verify, try: ruby19 -r readline -e 'puts Readline.readline, "DONE"' Press control-C before terminating the input line to be read via Readline.readline. Note that the signal is not processed until you finally terminate the line. The can also be observed in irb The attached causes the GNU readline library to call back into Ruby's I/O library for each byte read from STDIN rather than use GNU readline's default, direct "getc" function. Further discussion can be found at: [ruby-core]:4039 Almost three years ago... :-) - brent --------------040802060002000004020900 Content-Type: text/x-patch; name="readlineSignal.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="readlineSignal.patch" diff -ru ruby-1.9-07-10-02/CVS/Entries ruby-1.9.0-mbari/CVS/Entries --- ruby-1.9-07-10-02/CVS/Entries 2007-10-07 22:23:57.000000000 -0700 +++ ruby-1.9.0-mbari/CVS/Entries 2007-10-08 14:25:24.000000000 -0700 @@ -1 +1,3 @@ -D +D/ext//// +/version.h/1.1.2.1/Mon Oct 8 06:40:01 2007//Truby19 +/ChangeLog/1.1.2.1/Tue Oct 2 23:48:05 2007//Truby19 diff -ru ruby-1.9-07-10-02/ChangeLog ruby-1.9.0-mbari/ChangeLog --- ruby-1.9-07-10-02/ChangeLog 2007-10-02 16:48:05.000000000 -0700 +++ ruby-1.9.0-mbari/ChangeLog 2007-10-08 14:32:15.000000000 -0700 @@ -1,3 +1,9 @@ +Mon Oct 8 14:28:52 2006 Brent Roman + + * ext/readline/readline.c (readline_getc): supercedes readline_event + allows apps to process signals while awaiting keyboard input + [ruby-core:4039] + Tue Oct 2 20:16:55 2007 NAKAMURA Usaku * win32/win32.c (init_env): refactoring. remove unused code. diff -ru ruby-1.9-07-10-02/ext/readline/readline.c ruby-1.9.0-mbari/ext/readline/readline.c --- ruby-1.9-07-10-02/ext/readline/readline.c 2007-10-02 16:47:35.000000000 -0700 +++ ruby-1.9.0-mbari/ext/readline/readline.c 2007-10-08 14:40:47.000000000 -0700 @@ -29,6 +29,7 @@ #endif static VALUE mReadline; +static VALUE sysread; #define TOLOWER(c) (isupper(c) ? tolower(c) : c) @@ -46,17 +47,21 @@ # define rl_completion_matches completion_matches #endif -static int readline_event(void); static char **readline_attempted_completion_function(const char *text, int start, int end); static int -readline_event() +readline_getc(FILE *ignored) +/* + single byte read from STDIN via the Ruby I/O libraries + This approach allows signals to be handled while awaiting (keyboard) input +*/ { - rb_thread_schedule(); - return 0; + VALUE string = rb_funcall (rb_stdin, sysread, 1, INT2FIX(1)); + return RSTRING_PTR(string)[0]; } + static VALUE readline_readline(int argc, VALUE *argv, VALUE self) { @@ -703,6 +708,9 @@ { VALUE history, fcomp, ucomp; + sysread = rb_intern("sysread"); + rl_getc_function = readline_getc; + /* Allow conditional parsing of the ~/.inputrc file. */ rl_readline_name = "Ruby"; @@ -787,9 +795,6 @@ #endif rl_attempted_completion_function = readline_attempted_completion_function; -#ifdef HAVE_RL_EVENT_HOOK - rl_event_hook = readline_event; -#endif #ifdef HAVE_RL_CLEAR_SIGNALS rl_clear_signals(); #endif --------------040802060002000004020900--