summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-01-20 11:12:38 +0100
committerVictor Stinner <victor.stinner@gmail.com>2016-01-20 11:12:38 +0100
commitb3b0102d41c7b1a25493b51d5d83d080fb32735b (patch)
treef33e879b08501a4aaafd4a80185b9ac18b91a7ac /Python/errors.c
parent483293a1f99146de7cef730f90ce824c67dde20d (diff)
downloadcpython-b3b0102d41c7b1a25493b51d5d83d080fb32735b.tar.gz
Add _PyThreadState_UncheckedGet()
Issue #26154: Add a new private _PyThreadState_UncheckedGet() function which gets the current thread state, but don't call Py_FatalError() if it is NULL. Python 3.5.1 removed the _PyThreadState_Current symbol from the Python C API to no more expose complex and private atomic types. Atomic types depends on the compiler or can even depend on compiler options. The new function _PyThreadState_UncheckedGet() allows to get the variable value without having to care of the exact implementation of atomic types. Changes: * Replace direct usage of the _PyThreadState_Current variable with a call to _PyThreadState_UncheckedGet(). * In pystate.c, replace direct usage of the _PyThreadState_Current variable with the PyThreadState_GET() macro for readability. * Document also PyThreadState_Get() in pystate.h
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 7b67566727..5ff1e4c81a 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -152,13 +152,7 @@ PyErr_SetString(PyObject *exception, const char *string)
PyObject *
PyErr_Occurred(void)
{
- /* 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));
-
+ PyThreadState *tstate = _PyThreadState_UncheckedGet();
return tstate == NULL ? NULL : tstate->curexc_type;
}