diff -c -r Python-2.3.4.orig/Modules/readline.c Python-2.3.4/Modules/readline.c *** Python-2.3.4.orig/Modules/readline.c Thu Nov 13 02:42:13 2003 --- Python-2.3.4/Modules/readline.c Tue Nov 16 20:23:03 2004 *************** *** 11,16 **** --- 11,17 ---- #include #include #include + #include #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE) /* GNU readline() mistakenly sets the LC_CTYPE locale. *************** *** 294,300 **** "set_completer_delims(string) -> None\n\ set the readline word delimiters for tab-completion"); - /* Add a line to the history buffer */ static PyObject * --- 295,300 ---- *************** *** 591,596 **** --- 591,598 ---- { #ifdef SAVE_LOCALE char *saved_locale = strdup(setlocale(LC_CTYPE, NULL)); + if (!saved_locale) + Py_FatalError("not enough memory to save locale"); #endif using_history(); *************** *** 635,640 **** --- 637,708 ---- #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); + + completed_input_string = not_done_reading; + + 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(); + } + + if(has_input > 0) { + rl_callback_read_char(); + } + else if (errno == EINTR) { + int s; + PyEval_RestoreThread(_PyOS_ReadlineTState); + s = PyErr_CheckSignals(); + PyEval_SaveThread(); + 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 */ *************** *** 648,661 **** } - /* 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)) { --- 716,728 ---- } 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)) { *************** *** 664,672 **** --- 731,761 ---- sigrelse(SIGINT); #endif PyOS_setsig(SIGINT, old_inthandler); + *signal = 1; return NULL; } rl_event_hook = PyOS_InputHook; + 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; + + #ifdef SAVE_LOCALE + char *saved_locale = strdup(setlocale(LC_CTYPE, NULL)); + if (!saved_locale) + Py_FatalError("not enough memory to save locale"); + setlocale(LC_CTYPE, ""); + #endif if (sys_stdin != rl_instream || sys_stdout != rl_outstream) { rl_instream = sys_stdin; *************** *** 676,691 **** #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; --- 765,786 ---- #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; *************** *** 714,719 **** --- 809,818 ---- p[n+1] = '\0'; } free(q); + #ifdef SAVE_LOCALE + setlocale(LC_CTYPE, saved_locale); /* Restore locale */ + free(saved_locale); + #endif return p; } diff -c -r Python-2.3.4.orig/Python/bltinmodule.c Python-2.3.4/Python/bltinmodule.c *** Python-2.3.4.orig/Python/bltinmodule.c Mon Mar 29 06:57:01 2004 --- Python-2.3.4/Python/bltinmodule.c Mon Nov 15 22:39:35 2004 *************** *** 1586,1592 **** prompt); Py_XDECREF(po); if (s == NULL) { ! PyErr_SetNone(PyExc_KeyboardInterrupt); return NULL; } if (*s == '\0') { --- 1586,1593 ---- prompt); Py_XDECREF(po); if (s == NULL) { ! if (!PyErr_Occurred()) ! PyErr_SetNone(PyExc_KeyboardInterrupt); return NULL; } if (*s == '\0') { Only in Python-2.3.4/Python: bltinmodule.c.rej diff -c -r Python-2.3.4.orig/Python/ceval.c Python-2.3.4/Python/ceval.c *** Python-2.3.4.orig/Python/ceval.c Sun Jun 29 10:48:32 2003 --- Python-2.3.4/Python/ceval.c Mon Nov 15 22:40:50 2004 *************** *** 436,442 **** 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 --- 436,442 ---- 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 diff -c -r Python-2.3.4.orig/Python/pythonrun.c Python-2.3.4/Python/pythonrun.c *** Python-2.3.4.orig/Python/pythonrun.c Mon Mar 22 15:41:47 2004 --- Python-2.3.4/Python/pythonrun.c Mon Nov 15 22:43:06 2004 *************** *** 1447,1453 **** msg = "EOL while scanning single-quoted string"; break; case E_INTR: ! PyErr_SetNone(PyExc_KeyboardInterrupt); Py_XDECREF(v); return; case E_NOMEM: --- 1447,1454 ---- 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: Only in Python-2.3.4/Python: pythonrun.c.rej diff -c -r Python-2.3.4.orig/Python/thread_pthread.h Python-2.3.4/Python/thread_pthread.h *** Python-2.3.4.orig/Python/thread_pthread.h Tue Jul 22 11:20:49 2003 --- Python-2.3.4/Python/thread_pthread.h Mon Nov 15 22:43:39 2004 *************** *** 189,195 **** { pthread_t th; int status; - sigset_t oldmask, newmask; #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) pthread_attr_t attrs; #endif --- 189,194 ---- *************** *** 207,219 **** 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(PY_PTHREAD_D4) pthread_attr_default, --- 206,211 ---- *************** *** 237,245 **** (void *)arg #endif ); - - /* 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); --- 229,234 ---- Only in Python-2.3.4: autom4te.cache diff -c -r Python-2.3.4.orig/configure Python-2.3.4/configure *** Python-2.3.4.orig/configure Fri May 7 15:13:40 2004 --- Python-2.3.4/configure Mon Nov 15 22:53:23 2004 *************** *** 1,5 **** #! /bin/sh ! # From configure.in Revision: 1.427.4.12 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.57 for python 2.3. # --- 1,5 ---- #! /bin/sh ! # From configure.in Revision: 1.427.4.13 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.57 for python 2.3. # *************** *** 18172,18177 **** --- 18172,18241 ---- 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" *************** *** 18358,18363 **** --- 18422,18486 ---- 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 diff -c -r Python-2.3.4.orig/configure.in Python-2.3.4/configure.in *** Python-2.3.4.orig/configure.in Fri May 7 15:13:47 2004 --- Python-2.3.4/configure.in Mon Nov 15 22:17:06 2004 *************** *** 2799,2804 **** --- 2799,2809 ---- [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) *************** *** 2819,2824 **** --- 2824,2840 ---- AC_CHECK_LIB(readline, rl_completion_matches, 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, [ Only in Python-2.3.4: configure.in.rej diff -c -r Python-2.3.4.orig/pyconfig.h.in Python-2.3.4/pyconfig.h.in *** Python-2.3.4.orig/pyconfig.h.in Mon Mar 22 15:20:32 2004 --- Python-2.3.4/pyconfig.h.in Mon Nov 15 22:17:41 2004 *************** *** 360,365 **** --- 360,371 ---- /* 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 diff -c -r Python-2.3.4.orig/Misc/ACKS Python-2.3.4/Misc/ACKS *** Python-2.3.4.orig/Misc/ACKS Thu Jul 17 15:18:50 2003 --- Python-2.3.4/Misc/ACKS Mon Nov 15 22:18:35 2004 *************** *** 315,320 **** --- 315,321 ---- Andrew Kuchling Vladimir Kushnir Cameron Laird + Andrew Langmead Detlef Lannert Soren Larsen Piers Lauder