]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 2.58 from trunk (minus the cleanup):
authorGuido van Rossum <guido@python.org>
Tue, 7 Jan 2003 20:40:15 +0000 (20:40 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 7 Jan 2003 20:40:15 +0000 (20:40 +0000)
Fix from Michael Stone for SF bug #660476 and #513033 (bogus thread
state swaps in readline).

Misc/ACKS
Misc/NEWS
Modules/readline.c

index b8902eb3e1d82872bc7437cca01044f71fd59fc1..c7d68be99c4393d224e8a5e5d4abefd044e8b31b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -499,6 +499,7 @@ Frank Stajano
 Richard Stoakley
 Casper Stoel
 Peter Stoehr
+Michael Stone
 Ken Stox
 William Tanksley
 Christian Tanzer
index 1438082260281438534fb0c0341301511779234b..2fa1e6698fed26c7d54e104419169eb76542746d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1,3 +1,13 @@
+What's New in Python 2.2.3
+Release date: XX-XXX-2003
+==========================
+
+- XXX There's more, but nobody has updated NEWS so far.
+
+- Fixed broken threadstate swap in readline that could cause fatal
+  errors when a readline hook was being invoked while a background
+  thread was active.  (SF bugs #660476 and #513033.)
+
 What's New in Python 2.2.2 (final) ?
 Release date: 14-Oct-2002
 ====================================
index 8d324cf8aa8730ab20b1bfb3c0a3473572d0a7d1..3aa62724c1bbd844c78b53b4d8c8979f255176ce 100644 (file)
@@ -404,16 +404,14 @@ static struct PyMethodDef readline_methods[] =
 /* C function to call the Python hooks. */
 
 static int
-on_hook(PyObject *func, PyThreadState *tstate)
+on_hook(PyObject *func, PyThreadState **tstate)
 {
        int result = 0;
        if (func != NULL) {
                PyObject *r;
-               PyThreadState *save_tstate;
                /* Note that readline is called with the interpreter
                   lock released! */
-               save_tstate = PyThreadState_Swap(NULL);
-               PyEval_RestoreThread(tstate);
+               PyEval_RestoreThread(*tstate);
                r = PyObject_CallFunction(func, NULL);
                if (r == NULL)
                        goto error;
@@ -427,8 +425,7 @@ on_hook(PyObject *func, PyThreadState *tstate)
                PyErr_Clear();
                Py_XDECREF(r);
          done:
-               PyEval_SaveThread();
-               PyThreadState_Swap(save_tstate);
+               *tstate = PyEval_SaveThread();
        }
        return result;
 }
@@ -436,14 +433,14 @@ on_hook(PyObject *func, PyThreadState *tstate)
 static int
 on_startup_hook(void)
 {
-       return on_hook(startup_hook, startup_hook_tstate);
+       return on_hook(startup_hook, &startup_hook_tstate);
 }
 
 #ifdef HAVE_RL_PRE_INPUT_HOOK
 static int
 on_pre_input_hook(void)
 {
-       return on_hook(pre_input_hook, pre_input_hook_tstate);
+       return on_hook(pre_input_hook, &pre_input_hook_tstate);
 }
 #endif
 
@@ -455,10 +452,8 @@ on_completion(char *text, int state)
        char *result = NULL;
        if (completer != NULL) {
                PyObject *r;
-               PyThreadState *save_tstate;
                /* Note that readline is called with the interpreter
                   lock released! */
-               save_tstate = PyThreadState_Swap(NULL);
                PyEval_RestoreThread(completer_tstate);
                r = PyObject_CallFunction(completer, "si", text, state);
                if (r == NULL)
@@ -478,8 +473,7 @@ on_completion(char *text, int state)
                PyErr_Clear();
                Py_XDECREF(r);
          done:
-               PyEval_SaveThread();
-               PyThreadState_Swap(save_tstate);
+               completer_tstate = PyEval_SaveThread();
        }
        return result;
 }