diff options
author | Jeffrey Yasskin <jyasskin@gmail.com> | 2010-05-13 18:31:05 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2010-05-13 18:31:05 +0000 |
commit | a2109217d1e96e46c777ff4db7660c4aea072b4a (patch) | |
tree | 6418edd711430dedc91f0a26296b942f5986ccc8 /Python/errors.c | |
parent | 7fec29b96babbe8ac34811982f0c0182460d7ef8 (diff) | |
download | cpython-a2109217d1e96e46c777ff4db7660c4aea072b4a.tar.gz |
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.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/errors.c b/Python/errors.c index e98d7a946c..37669739c1 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; } |