summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2010-05-13 18:31:05 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2010-05-13 18:31:05 (GMT)
commit8e0bdfd1d473ddffaf3501768678f8a970019da8 (patch)
treedf31716c768c6512c72f40819f0cc752c7e742f4 /Python/errors.c
parentf55621115cb2b73f60e7396cbade18a89a80d989 (diff)
downloadcpython-8e0bdfd1d473ddffaf3501768678f8a970019da8.zip
cpython-8e0bdfd1d473ddffaf3501768678f8a970019da8.tar.gz
cpython-8e0bdfd1d473ddffaf3501768678f8a970019da8.tar.bz2
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.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/errors.c b/Python/errors.c
index e98d7a9..3766973 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -130,9 +130,14 @@ PyErr_SetString(PyObject *exception, const char *string)
PyObject *
PyErr_Occurred(void)
{
- PyThreadState *tstate = PyThreadState_GET();
-
- return tstate->curexc_type;
+ /* 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 == NULL ? NULL : tstate->curexc_type;
}