mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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:
parent
f55621115c
commit
8e0bdfd1d4
3 changed files with 34 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue