? autom4te.cache ? build-debug ? build-not ? ingmar.txt ? Lib/test/test_threadsignals.py ? Objects/listobject.c-mine ? Python/compile.c-mine Index: configure =================================================================== RCS file: /cvsroot/python/python/dist/src/configure,v retrieving revision 1.446 diff -c -r1.446 configure *** configure 8 Jun 2004 08:17:34 -0000 1.446 --- configure 18 Jun 2004 12:53:57 -0000 *************** *** 1,5 **** #! /bin/sh ! # From configure.in Revision: 1.456 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.57 for python 2.4. # --- 1,5 ---- #! /bin/sh ! # From configure.in Revision: 1.457 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.57 for python 2.4. # *************** *** 17384,17389 **** --- 17384,17453 ---- fi + # check for readline 2.1 + echo "$as_me:$LINENO: checking for rl_callback_handler_install in -lreadline" >&5 + echo $ECHO_N "checking for rl_callback_handler_install in -lreadline... $ECHO_C" >&6 + if test "${ac_cv_lib_readline_rl_callback_handler_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 + else + ac_check_lib_save_LIBS=$LIBS + LIBS="-lreadline -ltermcap $LIBS" + cat >conftest.$ac_ext <<_ACEOF + #line $LINENO "configure" + /* confdefs.h. */ + _ACEOF + cat confdefs.h >>conftest.$ac_ext + cat >>conftest.$ac_ext <<_ACEOF + /* end confdefs.h. */ + + /* Override any gcc2 internal prototype to avoid an error. */ + #ifdef __cplusplus + extern "C" + #endif + /* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ + char rl_callback_handler_install (); + int + main () + { + rl_callback_handler_install (); + ; + return 0; + } + _ACEOF + rm -f conftest.$ac_objext conftest$ac_exeext + if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_readline_rl_callback_handler_install=yes + else + echo "$as_me: failed program was:" >&5 + sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_readline_rl_callback_handler_install=no + fi + rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + LIBS=$ac_check_lib_save_LIBS + fi + echo "$as_me:$LINENO: result: $ac_cv_lib_readline_rl_callback_handler_install" >&5 + echo "${ECHO_T}$ac_cv_lib_readline_rl_callback_handler_install" >&6 + if test $ac_cv_lib_readline_rl_callback_handler_install = yes; then + + cat >>confdefs.h <<\_ACEOF + #define HAVE_RL_CALLBACK 1 + _ACEOF + + fi + + # check for readline 2.2 cat >conftest.$ac_ext <<_ACEOF #line $LINENO "configure" *************** *** 17571,17576 **** --- 17635,17699 ---- fi + # also in readline 4.2 + cat >conftest.$ac_ext <<_ACEOF + #line $LINENO "configure" + /* confdefs.h. */ + _ACEOF + cat confdefs.h >>conftest.$ac_ext + cat >>conftest.$ac_ext <<_ACEOF + /* end confdefs.h. */ + #include + _ACEOF + if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi + else + ac_cpp_err=yes + fi + if test -z "$ac_cpp_err"; then + have_readline=yes + else + echo "$as_me: failed program was:" >&5 + sed 's/^/| /' conftest.$ac_ext >&5 + + have_readline=no + fi + rm -f conftest.err conftest.$ac_ext + if test $have_readline = yes + then + cat >conftest.$ac_ext <<_ACEOF + #line $LINENO "configure" + /* confdefs.h. */ + _ACEOF + cat confdefs.h >>conftest.$ac_ext + cat >>conftest.$ac_ext <<_ACEOF + /* end confdefs.h. */ + #include + + _ACEOF + if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "extern int rl_catch_signals;" >/dev/null 2>&1; then + + cat >>confdefs.h <<\_ACEOF + #define HAVE_RL_CATCH_SIGNAL 1 + _ACEOF + + fi + rm -f conftest* + + fi + echo "$as_me:$LINENO: checking for broken nice()" >&5 echo $ECHO_N "checking for broken nice()... $ECHO_C" >&6 if test "${ac_cv_broken_nice+set}" = set; then Index: configure.in =================================================================== RCS file: /cvsroot/python/python/dist/src/configure.in,v retrieving revision 1.457 diff -c -r1.457 configure.in *** configure.in 8 Jun 2004 08:17:41 -0000 1.457 --- configure.in 18 Jun 2004 12:53:57 -0000 *************** *** 2765,2770 **** --- 2765,2775 ---- [Define this if you have flockfile(), getc_unlocked(), and funlockfile()]) fi + # check for readline 2.1 + AC_CHECK_LIB(readline, rl_callback_handler_install, + AC_DEFINE(HAVE_RL_CALLBACK, 1, + [Define if you have readline 2.1]), , -ltermcap) + # check for readline 2.2 AC_TRY_CPP([#include ], have_readline=yes, have_readline=no) *************** *** 2786,2791 **** --- 2791,2807 ---- AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, [Define if you have readline 4.2]), , -ltermcap) + # also in readline 4.2 + AC_TRY_CPP([#include ], + have_readline=yes, have_readline=no) + if test $have_readline = yes + then + AC_EGREP_HEADER([extern int rl_catch_signals;], + [readline/readline.h], + AC_DEFINE(HAVE_RL_CATCH_SIGNAL, 1, + [Define if you can turn off readline's signal handling.]), ) + fi + AC_MSG_CHECKING(for broken nice()) AC_CACHE_VAL(ac_cv_broken_nice, [ AC_TRY_RUN([ Index: pyconfig.h.in =================================================================== RCS file: /cvsroot/python/python/dist/src/pyconfig.h.in,v retrieving revision 1.97 diff -c -r1.97 pyconfig.h.in *** pyconfig.h.in 8 Jun 2004 08:17:41 -0000 1.97 --- pyconfig.h.in 18 Jun 2004 12:53:57 -0000 *************** *** 359,364 **** --- 359,370 ---- /* Define to 1 if you have the `realpath' function. */ #undef HAVE_REALPATH + /* Define if you have readline 2.1 */ + #undef HAVE_RL_CALLBACK + + /* Define if you can turn off readline's signal handling. */ + #undef HAVE_RL_CATCH_SIGNAL + /* Define if you have readline 2.2 */ #undef HAVE_RL_COMPLETION_APPEND_CHARACTER Index: Misc/ACKS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/ACKS,v retrieving revision 1.264 diff -c -r1.264 ACKS *** Misc/ACKS 10 Jun 2004 18:42:15 -0000 1.264 --- Misc/ACKS 18 Jun 2004 12:53:59 -0000 *************** *** 323,328 **** --- 323,329 ---- Andrew Kuchling Vladimir Kushnir Cameron Laird + Andrew Langmead Detlef Lannert Soren Larsen Piers Lauder Index: Modules/readline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v retrieving revision 2.70 diff -c -r2.70 readline.c *** Modules/readline.c 24 May 2004 14:20:15 -0000 2.70 --- Modules/readline.c 18 Jun 2004 12:53:59 -0000 *************** *** 656,661 **** --- 656,721 ---- #endif } + /* Wrapper around GNU readline that handles signals differently. */ + + + #if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) + + static char *completed_input_string; + static void + rlhandler(char *text) + { + completed_input_string = text; + rl_callback_handler_remove(); + } + + extern PyThreadState* _PyOS_ReadlineTState; + + static char * + readline_until_enter_or_signal(char *prompt, int *signal) + { + char * not_done_reading = ""; + fd_set selectset; + + *signal = 0; + #ifdef HAVE_RL_CATCH_SIGNAL + rl_catch_signals = 0; + #endif + + 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; + + has_input = select(fileno(rl_instream) + 1, &selectset, + NULL, NULL, NULL); + if(has_input > 0) { + rl_callback_read_char(); + } + else if (errno == EINTR) { + int s; + PyEval_RestoreThread(_PyOS_ReadlineTState); + s = PyErr_CheckSignals(); + PyThreadState_Swap(NULL); + if (s < 0) { + rl_free_line_state(); + rl_cleanup_after_signal(); + rl_callback_handler_remove(); + *signal = 1; + completed_input_string = NULL; + } + } + } + + return completed_input_string; + } + + + #else /* Interrupt handler */ *************** *** 669,682 **** } - /* Wrapper around GNU readline that handles signals differently. */ - static char * ! call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) { - size_t n; - char *p, *q; PyOS_sighandler_t old_inthandler; old_inthandler = PyOS_setsig(SIGINT, onintr); if (setjmp(jbuf)) { --- 729,741 ---- } static char * ! readline_until_enter_or_signal(char *prompt, int *signal) { PyOS_sighandler_t old_inthandler; + char *p; + + *signal = 0; old_inthandler = PyOS_setsig(SIGINT, onintr); if (setjmp(jbuf)) { *************** *** 685,692 **** --- 744,767 ---- sigrelse(SIGINT); #endif PyOS_setsig(SIGINT, old_inthandler); + *signal = 1; return NULL; } + p = readline(prompt); + PyOS_setsig(SIGINT, old_inthandler); + + return p; + } + #endif /*defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) */ + + + static char * + call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) + { + size_t n; + char *p, *q; + int signal; + rl_event_hook = PyOS_InputHook; if (sys_stdin != rl_instream || sys_stdout != rl_outstream) { *************** *** 697,712 **** #endif } ! p = readline(prompt); ! PyOS_setsig(SIGINT, old_inthandler); ! /* We must return a buffer allocated with PyMem_Malloc. */ if (p == NULL) { p = PyMem_Malloc(1); if (p != NULL) *p = '\0'; return p; } n = strlen(p); if (n > 0) { char *line; --- 772,793 ---- #endif } ! p = readline_until_enter_or_signal(prompt, &signal); ! ! /* we got an interrupt signal */ ! if(signal) { ! return NULL; ! } ! /* We got an EOF, return a empty string. */ if (p == NULL) { p = PyMem_Malloc(1); if (p != NULL) *p = '\0'; return p; } + + /* we have a valid line */ n = strlen(p); if (n > 0) { char *line; Index: Parser/myreadline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v retrieving revision 2.30 diff -c -r2.30 myreadline.c *** Parser/myreadline.c 19 Nov 2003 15:24:46 -0000 2.30 --- Parser/myreadline.c 18 Jun 2004 12:53:59 -0000 *************** *** 19,24 **** --- 19,26 ---- extern char* vms__StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt); #endif + PyThreadState* _PyOS_ReadlineTState; + int (*PyOS_InputHook)(void) = NULL; #ifdef RISCOS *************** *** 73,82 **** } #ifdef EINTR if (errno == EINTR) { ! if (PyOS_InterruptOccurred()) { ! return 1; /* Interrupt */ } - continue; } #endif if (PyOS_InterruptOccurred()) { --- 75,87 ---- } #ifdef EINTR if (errno == EINTR) { ! int s; ! PyEval_RestoreThread(_PyOS_ReadlineTState); ! s = PyErr_CheckSignals(); ! PyThreadState_Swap(NULL); ! if (s < 0) { ! return 1; } } #endif if (PyOS_InterruptOccurred()) { *************** *** 155,160 **** --- 160,172 ---- { char *rv; + if (_PyOS_ReadlineTState != NULL) { + PyErr_SetString(PyExc_RuntimeError, + "can't re-enter readline"); + return NULL; + } + + if (PyOS_ReadlineFunctionPointer == NULL) { #ifdef __VMS PyOS_ReadlineFunctionPointer = vms__StdioReadline; *************** *** 162,168 **** PyOS_ReadlineFunctionPointer = PyOS_StdioReadline; #endif } ! Py_BEGIN_ALLOW_THREADS /* This is needed to handle the unlikely case that the --- 174,181 ---- PyOS_ReadlineFunctionPointer = PyOS_StdioReadline; #endif } ! ! _PyOS_ReadlineTState = PyThreadState_GET(); Py_BEGIN_ALLOW_THREADS /* This is needed to handle the unlikely case that the *************** *** 176,180 **** --- 189,196 ---- rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout, prompt); Py_END_ALLOW_THREADS + + _PyOS_ReadlineTState = NULL; + return rv; } Index: Python/bltinmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v retrieving revision 2.309 diff -c -r2.309 bltinmodule.c *** Python/bltinmodule.c 29 Mar 2004 11:50:55 -0000 2.309 --- Python/bltinmodule.c 18 Jun 2004 12:53:59 -0000 *************** *** 1581,1587 **** prompt); Py_XDECREF(po); if (s == NULL) { ! PyErr_SetNone(PyExc_KeyboardInterrupt); return NULL; } if (*s == '\0') { --- 1581,1588 ---- prompt); Py_XDECREF(po); if (s == NULL) { ! if (!PyErr_Occurred()) ! PyErr_SetNone(PyExc_KeyboardInterrupt); return NULL; } if (*s == '\0') { Index: Python/ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.400 diff -c -r2.400 ceval.c *** Python/ceval.c 17 Jun 2004 10:22:40 -0000 2.400 --- Python/ceval.c 18 Jun 2004 12:53:59 -0000 *************** *** 320,326 **** int Py_AddPendingCall(int (*func)(void *), void *arg) { ! static int busy = 0; int i, j; /* XXX Begin critical section */ /* XXX If you want this to be safe against nested --- 320,326 ---- int Py_AddPendingCall(int (*func)(void *), void *arg) { ! static volatile int busy = 0; int i, j; /* XXX Begin critical section */ /* XXX If you want this to be safe against nested Index: Python/pythonrun.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v retrieving revision 2.205 diff -c -r2.205 pythonrun.c *** Python/pythonrun.c 24 Mar 2004 22:22:12 -0000 2.205 --- Python/pythonrun.c 18 Jun 2004 12:54:00 -0000 *************** *** 1435,1441 **** msg = "EOL while scanning single-quoted string"; break; case E_INTR: ! PyErr_SetNone(PyExc_KeyboardInterrupt); Py_XDECREF(v); return; case E_NOMEM: --- 1435,1442 ---- msg = "EOL while scanning single-quoted string"; break; case E_INTR: ! if (!PyErr_Occurred()) ! PyErr_SetNone(PyExc_KeyboardInterrupt); Py_XDECREF(v); return; case E_NOMEM: Index: Python/thread_pthread.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/thread_pthread.h,v retrieving revision 2.52 diff -c -r2.52 thread_pthread.h *** Python/thread_pthread.h 4 Mar 2004 06:35:57 -0000 2.52 --- Python/thread_pthread.h 18 Jun 2004 12:54:00 -0000 *************** *** 119,125 **** { pthread_t th; int status; - sigset_t oldmask, newmask; #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) pthread_attr_t attrs; #endif --- 119,124 ---- *************** *** 137,149 **** pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); #endif - /* Mask all signals in the current thread before creating the new - * thread. This causes the new thread to start with all signals - * blocked. - */ - sigfillset(&newmask); - SET_THREAD_SIGMASK(SIG_BLOCK, &newmask, &oldmask); - status = pthread_create(&th, #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) &attrs, --- 136,141 ---- *************** *** 154,162 **** (void *)arg ); - /* Restore signal mask for original thread */ - SET_THREAD_SIGMASK(SIG_SETMASK, &oldmask, NULL); - #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) pthread_attr_destroy(&attrs); #endif --- 146,151 ----