summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-07 18:51:41 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-07 18:51:41 (GMT)
commit0e8457c4ecf63ffc1826c30f27cbd4756c2b7101 (patch)
treeaddcdb163a6e6cf83476981f45a10d56348d4ddd
parent53ad776cbf21f21a314eda1cf1e61081b5f2fa53 (diff)
downloadcpython-0e8457c4ecf63ffc1826c30f27cbd4756c2b7101.zip
cpython-0e8457c4ecf63ffc1826c30f27cbd4756c2b7101.tar.gz
cpython-0e8457c4ecf63ffc1826c30f27cbd4756c2b7101.tar.bz2
Fix EventHook (the trick to make widgets appear when using GNU
readline) to create and use a new thread state object -- otherwise it would dump core!
-rw-r--r--Modules/_tkinter.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 1307053..19ed4f8 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -1451,17 +1451,30 @@ static PyMethodDef moduleMethods[] =
{NULL, NULL}
};
+static PyInterpreterState *event_interp = NULL;
+
static int
EventHook()
{
+ PyThreadState *tstate;
+
+ if (Tk_GetNumMainWindows() == 0)
+ return 0;
+ if (event_interp == NULL)
+ return 0;
+ tstate = PyThreadState_New(event_interp);
+ PyEval_AcquireThread(tstate);
+ if (!errorInCmd)
+ Tcl_DoOneEvent(TCL_DONT_WAIT);
if (errorInCmd) {
errorInCmd = 0;
PyErr_Restore(excInCmd, valInCmd, trbInCmd);
excInCmd = valInCmd = trbInCmd = NULL;
PyErr_Print();
}
- if (Tk_GetNumMainWindows() > 0)
- Tcl_DoOneEvent(TCL_DONT_WAIT);
+ PyThreadState_Clear(tstate);
+ PyEval_ReleaseThread(tstate);
+ PyThreadState_Delete(tstate);
return 0;
}
@@ -1522,8 +1535,11 @@ init_tkinter()
PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type);
PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
- if (PyOS_InputHook == NULL)
+ if (PyOS_InputHook == NULL) {
+ PyEval_InitThreads();
+ event_interp = PyThreadState_Get()->interp;
PyOS_InputHook = EventHook;
+ }
if (PyErr_Occurred())
Py_FatalError("can't initialize module _tkinter");