summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-01-20 10:19:46 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-01-20 10:19:46 (GMT)
commitb56837a03358ee2a3374fc0004488179c6771442 (patch)
tree59d848efeabdc78d807d2eb3c462635f7cf3876a /Python
parent5ccbf79eaea74814a16618879919ff470dc5131f (diff)
parentbfd316e750bc3040c08d1b5872e2de188e8c1e5f (diff)
downloadcpython-b56837a03358ee2a3374fc0004488179c6771442.zip
cpython-b56837a03358ee2a3374fc0004488179c6771442.tar.gz
cpython-b56837a03358ee2a3374fc0004488179c6771442.tar.bz2
Merge 3.5
Issue #26154: Add a new private _PyThreadState_UncheckedGet() function.
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c8
-rw-r--r--Python/pystate.c33
-rw-r--r--Python/sysmodule.c2
3 files changed, 22 insertions, 21 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 7b67566..5ff1e4c 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;
}
diff --git a/Python/pystate.c b/Python/pystate.c
index 50edfbb..6d0696d 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -3,6 +3,12 @@
#include "Python.h"
+#ifndef Py_BUILD_CORE
+/* ensure that PyThreadState_GET() is a macro, not an alias to
+ * PyThreadState_Get() */
+# error "pystate.c must be compiled with Py_BUILD_CORE defined"
+#endif
+
/* --------------------------------------------------------------------------
CAUTION
@@ -423,7 +429,7 @@ tstate_delete_common(PyThreadState *tstate)
void
PyThreadState_Delete(PyThreadState *tstate)
{
- if (tstate == (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current))
+ if (tstate == PyThreadState_GET())
Py_FatalError("PyThreadState_Delete: tstate is still current");
#ifdef WITH_THREAD
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
@@ -437,8 +443,7 @@ PyThreadState_Delete(PyThreadState *tstate)
void
PyThreadState_DeleteCurrent()
{
- PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed(
- &_PyThreadState_Current);
+ PyThreadState *tstate = PyThreadState_GET();
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
@@ -489,10 +494,16 @@ _PyThreadState_DeleteExcept(PyThreadState *tstate)
PyThreadState *
+_PyThreadState_UncheckedGet(void)
+{
+ return PyThreadState_GET();
+}
+
+
+PyThreadState *
PyThreadState_Get(void)
{
- PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed(
- &_PyThreadState_Current);
+ PyThreadState *tstate = PyThreadState_GET();
if (tstate == NULL)
Py_FatalError("PyThreadState_Get: no current thread");
@@ -503,8 +514,7 @@ PyThreadState_Get(void)
PyThreadState *
PyThreadState_Swap(PyThreadState *newts)
{
- PyThreadState *oldts = (PyThreadState*)_Py_atomic_load_relaxed(
- &_PyThreadState_Current);
+ PyThreadState *oldts = PyThreadState_GET();
_Py_atomic_store_relaxed(&_PyThreadState_Current, newts);
/* It should not be possible for more than one thread state
@@ -535,8 +545,7 @@ PyThreadState_Swap(PyThreadState *newts)
PyObject *
PyThreadState_GetDict(void)
{
- PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed(
- &_PyThreadState_Current);
+ PyThreadState *tstate = PyThreadState_GET();
if (tstate == NULL)
return NULL;
@@ -682,7 +691,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
{
/* Must be the tstate for this thread */
assert(PyGILState_GetThisThreadState()==tstate);
- return tstate == (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current);
+ return tstate == PyThreadState_GET();
}
/* Internal initialization/finalization functions called by
@@ -774,9 +783,7 @@ PyGILState_GetThisThreadState(void)
int
PyGILState_Check(void)
{
- /* can't use PyThreadState_Get() since it will assert that it has the GIL */
- PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed(
- &_PyThreadState_Current);
+ PyThreadState *tstate = PyThreadState_GET();
return tstate && (tstate == PyGILState_GetThisThreadState());
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 53dd4a1..702e8f0 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1396,7 +1396,7 @@ error:
Py_XDECREF(name);
Py_XDECREF(value);
/* No return value, therefore clear error state if possible */
- if (_Py_atomic_load_relaxed(&_PyThreadState_Current))
+ if (_PyThreadState_UncheckedGet())
PyErr_Clear();
}