Make PyErr_Occurred return NULL if there is no current thread. Previously it

would Py_FatalError, which called PyErr_Occurred, resulting in a semi-infinite
recursion.

Fixes issue 3605.
This commit is contained in:
Jeffrey Yasskin 2010-05-13 18:31:05 +00:00
parent f55621115c
commit 8e0bdfd1d4
3 changed files with 34 additions and 3 deletions

View file

@ -130,9 +130,14 @@ PyErr_SetString(PyObject *exception, const char *string)
PyObject *
PyErr_Occurred(void)
{
PyThreadState *tstate = PyThreadState_GET();
/* If there is no thread state, PyThreadState_GET calls
Py_FatalError, which calls PyErr_Occurred. To avoid the
resulting infinite loop, we inline PyThreadState_GET here and
treat no thread as no error. */
PyThreadState *tstate =
((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current));
return tstate->curexc_type;
return tstate == NULL ? NULL : tstate->curexc_type;
}