From 8e0bdfd1d473ddffaf3501768678f8a970019da8 Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Thu, 13 May 2010 18:31:05 +0000 Subject: 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. --- Python/errors.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index e98d7a946ca..37669739c15 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; } -- cgit v1.2.3