Index: Python/bltinmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v retrieving revision 2.282 diff -c -r2.282 bltinmodule.c *** Python/bltinmodule.c 23 Feb 2003 21:45:43 -0000 2.282 --- Python/bltinmodule.c 19 Mar 2003 17:21:36 -0000 *************** *** 1383,1389 **** prompt); Py_XDECREF(po); if (s == NULL) { - PyErr_SetNone(PyExc_KeyboardInterrupt); return NULL; } if (*s == '\0') { --- 1383,1388 ---- Index: Python/pythonrun.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v retrieving revision 2.181 diff -c -r2.181 pythonrun.c *** Python/pythonrun.c 5 Mar 2003 17:31:21 -0000 2.181 --- Python/pythonrun.c 19 Mar 2003 17:21:44 -0000 *************** *** 1304,1310 **** msg = "EOL while scanning single-quoted string"; break; case E_INTR: ! PyErr_SetNone(PyExc_KeyboardInterrupt); Py_XDECREF(v); return; case E_NOMEM: --- 1304,1310 ---- msg = "EOL while scanning single-quoted string"; break; case E_INTR: ! /* Exception should have been set by interrupt handler */ Py_XDECREF(v); return; case E_NOMEM: Index: Modules/signalmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/signalmodule.c,v retrieving revision 2.73 diff -c -r2.73 signalmodule.c *** Modules/signalmodule.c 13 Mar 2003 13:56:53 -0000 2.73 --- Modules/signalmodule.c 19 Mar 2003 17:21:47 -0000 *************** *** 667,669 **** --- 667,704 ---- main_pid = getpid(); #endif } + + void + PyOS_triggersig(int sig) + { + is_tripped++; + Handlers[sig].tripped = 1; + Py_AddPendingCall((int (*)(void *))PyErr_CheckSignals, NULL); + } + + void + PyOS_filtersigs(void (*handler)(int)) + { + int i; + for (i = 1; i < NSIG; i++) + if (Handlers[i].func != DefaultHandler + && Handlers[i].func != IgnoreHandler + && Handlers[i].func != Py_None) + PyOS_setsig(i, handler); + } + + void + PyOS_unfiltersigs() + { + int i; + for (i = 1; i < NSIG; i++) + if (Handlers[i].func != DefaultHandler + && Handlers[i].func != IgnoreHandler + && Handlers[i].func != Py_None) { + #ifdef HAVE_SIGRELSE + /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */ + sigrelse(SIGINT); + #endif + PyOS_setsig(i, signal_handler); + } + } Index: Modules/readline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v retrieving revision 2.62 diff -c -r2.62 readline.c *** Modules/readline.c 1 Mar 2003 15:19:41 -0000 2.62 --- Modules/readline.c 19 Mar 2003 17:21:53 -0000 *************** *** 521,529 **** --- 521,540 ---- return result; } + char *continuing = NULL; + int point, mark; + static int on_startup_hook(void) { + if (continuing) { + rl_on_new_line(); + rl_insert_text(continuing); + rl_point = point; + rl_mark = mark; + free(continuing); + continuing = NULL; + } return on_hook(startup_hook, &startup_hook_tstate); } *************** *** 641,653 **** /* Interrupt handler */ ! static jmp_buf jbuf; /* ARGSUSED */ static void onintr(int sig) { ! longjmp(jbuf, 1); } --- 652,664 ---- /* Interrupt handler */ ! static sigjmp_buf jbuf; /* ARGSUSED */ static void onintr(int sig) { ! siglongjmp(jbuf, sig); } *************** *** 658,673 **** { size_t n; char *p, *q; ! PyOS_sighandler_t old_inthandler; ! old_inthandler = PyOS_setsig(SIGINT, onintr); ! if (setjmp(jbuf)) { ! #ifdef HAVE_SIGRELSE ! /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */ ! sigrelse(SIGINT); ! #endif ! PyOS_setsig(SIGINT, old_inthandler); ! return NULL; } rl_event_hook = PyOS_InputHook; --- 669,690 ---- { size_t n; char *p, *q; ! int triggered; ! PyOS_filtersigs(onintr); ! Py_BEGIN_ALLOW_THREADS ! if ((triggered = sigsetjmp(jbuf, 1)) != 0) { ! Py_BLOCK_THREADS ! PyOS_unfiltersigs(); ! PyOS_triggersig(triggered); ! if (PyErr_CheckSignals()) ! return NULL; ! fprintf(sys_stdout, "\r"); ! continuing = strdup(rl_line_buffer); ! point = rl_point; ! mark = rl_mark; ! PyOS_filtersigs(onintr); ! Py_UNBLOCK_THREADS } rl_event_hook = PyOS_InputHook; *************** *** 680,686 **** } p = readline(prompt); ! PyOS_setsig(SIGINT, old_inthandler); /* We must return a buffer allocated with PyMem_Malloc. */ if (p == NULL) { --- 697,704 ---- } p = readline(prompt); ! Py_END_ALLOW_THREADS ! PyOS_unfiltersigs(); /* We must return a buffer allocated with PyMem_Malloc. */ if (p == NULL) { Index: Parser/myreadline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v retrieving revision 2.28 diff -c -r2.28 myreadline.c *** Parser/myreadline.c 26 Oct 2002 14:39:09 -0000 2.28 --- Parser/myreadline.c 19 Mar 2003 17:21:54 -0000 *************** *** 29,38 **** --- 29,42 ---- { char *p; for (;;) { + + Py_BEGIN_ALLOW_THREADS if (PyOS_InputHook != NULL) (void)(PyOS_InputHook)(); errno = 0; p = fgets(buf, len, fp); + Py_END_ALLOW_THREADS + if (p != NULL) return 0; /* No error */ #ifdef MS_WINDOWS *************** *** 52,58 **** signal may be treated as a separate interrupt). */ Sleep(1); ! if (PyOS_InterruptOccurred()) { return 1; /* Interrupt */ } /* Either the sleep wasn't long enough (need a --- 56,62 ---- signal may be treated as a separate interrupt). */ Sleep(1); ! if (PyErr_CheckSignals()) { return 1; /* Interrupt */ } /* Either the sleep wasn't long enough (need a *************** *** 69,81 **** } #ifdef EINTR if (errno == EINTR) { ! if (PyOS_InterruptOccurred()) { return 1; /* Interrupt */ } continue; } #endif ! if (PyOS_InterruptOccurred()) { return 1; /* Interrupt */ } return -2; /* Error */ --- 73,85 ---- } #ifdef EINTR if (errno == EINTR) { ! if (PyErr_CheckSignals()) { return 1; /* Interrupt */ } continue; } #endif ! if (PyErr_CheckSignals()) { return 1; /* Interrupt */ } return -2; /* Error */ *************** *** 162,169 **** PyOS_ReadlineFunctionPointer = PyOS_StdioReadline; } - Py_BEGIN_ALLOW_THREADS - /* This is needed to handle the unlikely case that the * interpreter is in interactive mode *and* stdin/out are not * a tty. This can happen, for example if python is run like --- 166,171 ---- *************** *** 174,179 **** else rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout, prompt); - Py_END_ALLOW_THREADS return rv; } --- 176,180 ---- Index: Include/intrcheck.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/intrcheck.h,v retrieving revision 2.10 diff -c -r2.10 intrcheck.h *** Include/intrcheck.h 12 Aug 2002 07:21:57 -0000 2.10 --- Include/intrcheck.h 19 Mar 2003 17:21:55 -0000 *************** *** 8,13 **** --- 8,16 ---- PyAPI_FUNC(int) PyOS_InterruptOccurred(void); PyAPI_FUNC(void) PyOS_InitInterrupts(void); PyAPI_FUNC(void) PyOS_AfterFork(void); + PyAPI_FUNC(void) PyOS_triggersig(int); + PyAPI_FUNC(void) PyOS_filtersigs(void (*)(int)); + PyAPI_FUNC(void) PyOS_unfiltersigs(void); #ifdef __cplusplus }