[Python-checkins] bpo-43268: Replace _PyThreadState_GET() with _PyInterpreterState_GET() (GH-24576)
vstinner
webhook-mailer at python.org
Fri Feb 19 07:21:32 EST 2021
https://github.com/python/cpython/commit/5592f2b9daa24bf74cc616abcc40a29da2bdccb2
commit: 5592f2b9daa24bf74cc616abcc40a29da2bdccb2
branch: master
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-02-19T13:21:28+01:00
summary:
bpo-43268: Replace _PyThreadState_GET() with _PyInterpreterState_GET() (GH-24576)
Replace _PyThreadState_GET() with _PyInterpreterState_GET() in
functions which only need the current interpreter, but don't need the
current Python thread state.
Replace also _PyThreadState_UncheckedGet() with _PyThreadState_GET()
in faulthandler.c, since _PyThreadState_UncheckedGet() is just an
alias to _PyThreadState_GET() in practice.
files:
M Include/internal/pycore_long.h
M Include/internal/pycore_object.h
M Modules/faulthandler.c
diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h
index ec95786531c85..a785b23a92b8c 100644
--- a/Include/internal/pycore_long.h
+++ b/Include/internal/pycore_long.h
@@ -14,13 +14,10 @@ extern "C" {
// Don't call this function but _PyLong_GetZero() and _PyLong_GetOne()
static inline PyObject* __PyLong_GetSmallInt_internal(int value)
{
- PyThreadState *tstate = _PyThreadState_GET();
-#ifdef Py_DEBUG
- _Py_EnsureTstateNotNULL(tstate);
-#endif
+ PyInterpreterState *interp = _PyInterpreterState_GET();
assert(-_PY_NSMALLNEGINTS <= value && value < _PY_NSMALLPOSINTS);
size_t index = _PY_NSMALLNEGINTS + value;
- PyObject *obj = (PyObject*)tstate->interp->small_ints[index];
+ PyObject *obj = (PyObject*)interp->small_ints[index];
// _PyLong_GetZero() and _PyLong_GetOne() must not be called
// before _PyLong_Init() nor after _PyLong_Fini()
assert(obj != NULL);
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 3cd27b035c2c7..79c1c44ae72d6 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -8,9 +8,9 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
-#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
-#include "pycore_interp.h" // PyInterpreterState.gc
-#include "pycore_pystate.h" // _PyThreadState_GET()
+#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
+#include "pycore_interp.h" // PyInterpreterState.gc
+#include "pycore_pystate.h" // _PyInterpreterState_GET()
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
@@ -85,8 +85,8 @@ static inline void _PyObject_GC_TRACK(
"object is in generation which is garbage collected",
filename, lineno, __func__);
- PyThreadState *tstate = _PyThreadState_GET();
- PyGC_Head *generation0 = tstate->interp->gc.generation0;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyGC_Head *generation0 = interp->gc.generation0;
PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
_PyGCHead_SET_NEXT(last, gc);
_PyGCHead_SET_PREV(gc, last);
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index da8b7741345de..350f4cf6b8edf 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -1,6 +1,7 @@
#include "Python.h"
#include "pycore_initconfig.h" // _PyStatus_ERR
#include "pycore_pyerrors.h" // _Py_DumpExtensionModules
+#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_traceback.h" // _Py_DumpTracebackThreads
#include <signal.h>
#include <object.h>
@@ -208,7 +209,7 @@ faulthandler_get_fileno(PyObject **file_ptr)
static PyThreadState*
get_thread_state(void)
{
- PyThreadState *tstate = _PyThreadState_UncheckedGet();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
/* just in case but very unlikely... */
PyErr_SetString(PyExc_RuntimeError,
More information about the Python-checkins
mailing list