diff options
author | Michael W. Hudson <mwh@python.net> | 2004-10-07 13:46:33 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2004-10-07 13:46:33 (GMT) |
commit | 8da2b01c3fb730c384cdc4e329933ee16cfe3497 (patch) | |
tree | a0af9d2cdd0d6267a6ab1c288e1b24e30fb2dc20 /Modules/readline.c | |
parent | 3afe4f371c0c1d303ddee8dbd07c211949d211ca (diff) | |
download | cpython-8da2b01c3fb730c384cdc4e329933ee16cfe3497.zip cpython-8da2b01c3fb730c384cdc4e329933ee16cfe3497.tar.gz cpython-8da2b01c3fb730c384cdc4e329933ee16cfe3497.tar.bz2 |
This is Michiel de Hoon's patch, as attached to the bug report:
[ 1030629 ] PyOS_InputHook broken
with a couple of utterly inconsequential changes by me.
Diffstat (limited to 'Modules/readline.c')
-rw-r--r-- | Modules/readline.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Modules/readline.c b/Modules/readline.c index a62244d..3377c8ea 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -11,6 +11,7 @@ #include <setjmp.h> #include <signal.h> #include <errno.h> +#include <sys/time.h> #if defined(HAVE_SETLOCALE) /* GNU readline() mistakenly sets the LC_CTYPE locale. @@ -749,15 +750,21 @@ readline_until_enter_or_signal(char *prompt, int *signal) rl_callback_handler_install (prompt, rlhandler); FD_ZERO(&selectset); - FD_SET(fileno(rl_instream), &selectset); completed_input_string = not_done_reading; - while(completed_input_string == not_done_reading) { - int has_input; + while (completed_input_string == not_done_reading) { + int has_input = 0; + + while (!has_input) + { struct timeval timeout = {0, 100000}; /* 0.1 seconds */ + FD_SET(fileno(rl_instream), &selectset); + /* select resets selectset if no input was available */ + has_input = select(fileno(rl_instream) + 1, &selectset, + NULL, NULL, &timeout); + if(PyOS_InputHook) PyOS_InputHook(); + } - has_input = select(fileno(rl_instream) + 1, &selectset, - NULL, NULL, NULL); if(has_input > 0) { rl_callback_read_char(); } @@ -812,6 +819,7 @@ readline_until_enter_or_signal(char *prompt, int *signal) *signal = 1; return NULL; } + rl_event_hook = PyOS_InputHook; p = readline(prompt); PyOS_setsig(SIGINT, old_inthandler); @@ -834,8 +842,6 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) setlocale(LC_CTYPE, ""); #endif - rl_event_hook = PyOS_InputHook; - if (sys_stdin != rl_instream || sys_stdout != rl_outstream) { rl_instream = sys_stdin; rl_outstream = sys_stdout; |