commit 484360d4420f14344254e89564b558e29b92fc9a Author: Michael Abbott Date: Mon Jun 23 17:01:25 2008 +0100 Initial patch for PyOS_InputHook interrupt handling diff --git a/Include/pythonrun.h b/Include/pythonrun.h index b2b3afd..d0ca05f 100644 --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -144,7 +144,7 @@ PyAPI_FUNC(void) PyByteArray_Fini(void); /* Stuff with no proper home (yet) */ PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *); -PyAPI_DATA(int) (*PyOS_InputHook)(void); +PyAPI_DATA(int) (*PyOS_InputHook)(int); PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *); PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index f101450..fba49c5 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -2992,18 +2992,14 @@ static PyThreadState *event_tstate = NULL; #endif static int -EventHook(void) +EventHook(int tfile) { -#ifndef MS_WINDOWS - int tfile; -#endif #ifdef WITH_THREAD PyEval_RestoreThread(event_tstate); #endif stdin_ready = 0; errorInCmd = 0; #ifndef MS_WINDOWS - tfile = fileno(stdin); Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL); #endif while (!errorInCmd && !stdin_ready) { diff --git a/Modules/readline.c b/Modules/readline.c index 90904ab..50b4e04 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -855,13 +855,19 @@ readline_until_enter_or_signal(char *prompt, int *signal) /* select resets selectset if no input was available */ has_input = select(fileno(rl_instream) + 1, &selectset, NULL, NULL, timeoutp); - if(PyOS_InputHook) PyOS_InputHook(); + if(PyOS_InputHook && + PyOS_InputHook(fileno(rl_instream))) + { + has_input = -1; + PyErr_SetInterrupt(); + break; + } } if(has_input > 0) { rl_callback_read_char(); } - else if (errno == EINTR) { + else if (errno == EINTR || has_input < 0) { int s; #ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); @@ -898,6 +904,15 @@ onintr(int sig) } +/* Simple wrapper for PyOS_InputHook designed to be compatible with the + * rl_event_hook readline mechanism. */ +static int call_input_hook() +{ + /* Interrupt handling not supported in this branch, alas. */ + (void) PyOS_InputHook(fileno(rl_instream)); + return 0; +} + static char * readline_until_enter_or_signal(char *prompt, int *signal) { @@ -916,7 +931,7 @@ readline_until_enter_or_signal(char *prompt, int *signal) *signal = 1; return NULL; } - rl_event_hook = PyOS_InputHook; + rl_event_hook = PyOS_InputHook ? call_input_hook : NULL; p = readline(prompt); PyOS_setsig(SIGINT, old_inthandler); diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 32a1088..de7939b 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -27,7 +27,7 @@ PyThreadState* _PyOS_ReadlineTState; static PyThread_type_lock _PyOS_ReadlineLock = NULL; #endif -int (*PyOS_InputHook)(void) = NULL; +int (*PyOS_InputHook)(int) = NULL; #ifdef RISCOS int Py_RISCOSWimpFlag; @@ -42,7 +42,8 @@ my_fgets(char *buf, int len, FILE *fp) char *p; for (;;) { if (PyOS_InputHook != NULL) - (void)(PyOS_InputHook)(); + /* Interrupt handling not implemented here yet. */ + (void) PyOS_InputHook(fileno(fp)); errno = 0; p = fgets(buf, len, fp); if (p != NULL)