mirror of
https://github.com/python/cpython.git
synced 2025-11-13 23:46:24 +00:00
Darn. When thread support is disabled, the BEGIN/END macros don't
save and restore the tstate, but explicitly calling PyEval_SaveThread() does reset it! While I think about how to fix this for real, here's a fix that avoids getting a fatal error.
This commit is contained in:
parent
04d5c5827a
commit
a59406abdf
2 changed files with 8 additions and 4 deletions
|
|
@ -1456,14 +1456,15 @@ static PyInterpreterState *event_interp = NULL;
|
||||||
static int
|
static int
|
||||||
EventHook()
|
EventHook()
|
||||||
{
|
{
|
||||||
PyThreadState *tstate;
|
PyThreadState *tstate, *save_tstate;
|
||||||
|
|
||||||
if (Tk_GetNumMainWindows() == 0)
|
if (Tk_GetNumMainWindows() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (event_interp == NULL)
|
if (event_interp == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
tstate = PyThreadState_New(event_interp);
|
tstate = PyThreadState_New(event_interp);
|
||||||
PyEval_AcquireThread(tstate);
|
save_tstate = PyThreadState_Swap(NULL);
|
||||||
|
PyEval_RestoreThread(tstate);
|
||||||
if (!errorInCmd)
|
if (!errorInCmd)
|
||||||
Tcl_DoOneEvent(TCL_DONT_WAIT);
|
Tcl_DoOneEvent(TCL_DONT_WAIT);
|
||||||
if (errorInCmd) {
|
if (errorInCmd) {
|
||||||
|
|
@ -1473,7 +1474,8 @@ EventHook()
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
}
|
}
|
||||||
PyThreadState_Clear(tstate);
|
PyThreadState_Clear(tstate);
|
||||||
PyEval_ReleaseThread(tstate);
|
PyEval_SaveThread();
|
||||||
|
PyThreadState_Swap(save_tstate);
|
||||||
PyThreadState_Delete(tstate);
|
PyThreadState_Delete(tstate);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1536,7 +1538,6 @@ init_tkinter()
|
||||||
PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
|
PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
|
||||||
|
|
||||||
if (PyOS_InputHook == NULL) {
|
if (PyOS_InputHook == NULL) {
|
||||||
PyEval_InitThreads();
|
|
||||||
event_interp = PyThreadState_Get()->interp;
|
event_interp = PyThreadState_Get()->interp;
|
||||||
PyOS_InputHook = EventHook;
|
PyOS_InputHook = EventHook;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,8 +168,10 @@ on_completion(text, state)
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
if (completer != NULL) {
|
if (completer != NULL) {
|
||||||
PyObject *r;
|
PyObject *r;
|
||||||
|
PyThreadState *save_tstate;
|
||||||
/* Note that readline is called with the interpreter
|
/* Note that readline is called with the interpreter
|
||||||
lock released! */
|
lock released! */
|
||||||
|
save_tstate = PyThreadState_Swap(NULL);
|
||||||
PyEval_RestoreThread(tstate);
|
PyEval_RestoreThread(tstate);
|
||||||
r = PyObject_CallFunction(completer, "si", text, state);
|
r = PyObject_CallFunction(completer, "si", text, state);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
|
|
@ -190,6 +192,7 @@ on_completion(text, state)
|
||||||
Py_XDECREF(r);
|
Py_XDECREF(r);
|
||||||
done:
|
done:
|
||||||
PyEval_SaveThread();
|
PyEval_SaveThread();
|
||||||
|
PyThreadState_Swap(save_tstate);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue