diff Python/errors.c @ 61555:1698c55b2af9

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.
author Jeffrey Yasskin <jyasskin@gmail.com>
date Thu, 13 May 2010 18:31:05 +0000
parents cab14be0ada1
children 600c23127207
line wrap: on
line diff
--- a/Python/errors.c	Thu May 13 16:23:09 2010 +0000
+++ b/Python/errors.c	Thu May 13 18:31:05 2010 +0000
@@ -130,9 +130,14 @@
 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;
 }