8000 Do not use _PyThreadState_GET() in pystate.c. · python/cpython@2f8aaec · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f8aaec

Browse files
Do not use _PyThreadState_GET() in pystate.c.
1 parent 6281edb commit 2f8aaec

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Python/pystate.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "pycore_pyerrors.h"
1111
#include "pycore_pylifecycle.h"
1212
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
13-
#include "pycore_pystate.h" // _PyThreadState_GET()
13+
#include "pycore_pystate.h"
1414
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
1515
#include "pycore_sysmodule.h"
1616

@@ -391,7 +391,8 @@ PyInterpreterState *
391391
PyInterpreterState_New(void)
392392
{
393393
PyInterpreterState *interp;
394-
PyThreadState *tstate = _PyThreadState_GET();
394+
_PyRuntimeState *runtime = &_PyRuntime;
395+
PyThreadState *tstate = current_fast_get(runtime);
395396

396397
/* tstate is NULL when Py_InitializeFromConfig() calls
397398
PyInterpreterState_New() to create the main interpreter. */
@@ -408,7 +409,6 @@ PyInterpreterState_New(void)
408409
}
409410

410411
/* Don't get runtime from tstate since tstate can be NULL. */
411-
_PyRuntimeState *runtime = &_PyRuntime;
412412
struct pyinterpreters *interpreters = &runtime->interpreters;
413413

414414
/* We completely serialize creation of multiple interpreters, since
@@ -556,7 +556,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
556556
// Use the current Python thread state to call audit hooks and to collect
557557
// garbage. It can be different than the current Python thread state
558558
// of 'interp'.
559-
PyThreadState *current_tstate = _PyThreadState_GET();
559+
PyThreadState *current_tstate = current_fast_get(interp->runtime);
560560

561561
interpreter_clear(interp, current_tstate);
562562
}
@@ -672,7 +672,7 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime)
672672
PyInterpreterState *
673673
PyInterpreterState_Get(void)
674674
{
675-
PyThreadState *tstate = _PyThreadState_GET();
675+
PyThreadState *tstate = current_fast_get(&_PyRuntime);
676676
_Py_EnsureTstateNotNULL(tstate);
677677
PyInterpreterState *interp = tstate->interp;
678678
if (interp == NULL) {
@@ -1040,7 +1040,7 @@ PyState_AddModule(PyObject* module, PyModuleDef* def)
10401040
return -1;
10411041
}
10421042

1043-
PyThreadState *tstate = _PyThreadState_GET();
1043+
PyThreadState *tstate = current_fast_get(&_PyRuntime);
10441044
PyInterpreterState *interp = tstate->interp;
10451045
Py_ssize_t index = def->m_base.m_index;
10461046
if (interp->modules_by_index &&
@@ -1056,7 +1056,7 @@ PyState_AddModule(PyObject* module, PyModuleDef* def)
10561056
int
10571057
PyState_RemoveModule(PyModuleDef* def)
10581058
{
1059-
PyThreadState *tstate = _PyThreadState_GET();
1059+
PyThreadState *tstate = current_fast_get(&_PyRuntime);
10601060
PyInterpreterState *interp = tstate->interp;
10611061

10621062
if (def->m_slots) {
@@ -1282,14 +1282,14 @@ _PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
12821282
PyThreadState *
12831283
_PyThreadState_UncheckedGet(void)
12841284
{
1285-
return _PyThreadState_GET();
1285+
return current_fast_get(&_PyRuntime);
12861286
}
12871287

12881288

12891289
PyThreadState *
12901290
PyThreadState_Get(void)
12911291
{
1292-
PyThreadState *tstate = _PyThreadState_GET();
1292+
PyThreadState *tstate = current_fast_get(&_PyRuntime);
12931293
_Py_EnsureTstateNotNULL(tstate);
12941294
return tstate;
12951295
}
@@ -1355,7 +1355,7 @@ _PyThreadState_GetDict(PyThreadState *tstate)
13551355
PyObject *
13561356
PyThreadState_GetDict(void)
13571357
{
1358-
PyThreadState *tstate = _PyThreadState_GET();
1358+
PyThreadState *tstate = current_fast_get(&_PyRuntime);
13591359
if (tstate == NULL) {
13601360
return NULL;
13611361
}
@@ -1478,7 +1478,8 @@ PyThreadState_Next(PyThreadState *tstate) {
14781478
PyObject *
14791479
_PyThread_CurrentFrames(void)
14801480
{
1481-
PyThreadState *tstate = _PyThreadState_GET();
1481+
_PyRuntimeState *runtime = &_PyRuntime;
1482+
PyThreadState *tstate = current_fast_get(runtime);
14821483
if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) {
14831484
return NULL;
14841485
}
@@ -1494,7 +1495,6 @@ _PyThread_CurrentFrames(void)
14941495
* Because these lists can mutate even when the GIL is held, we
14951496
* need to grab head_mutex for the duration.
14961497
*/
1497-
_PyRuntimeState *runtime = tstate->interp->runtime;
14981498
HEAD_LOCK(runtime);
14991499
PyInterpreterState *i;
15001500
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
@@ -1534,7 +1534,8 @@ _PyThread_CurrentFrames(void)
15341534
PyObject *
15351535
_PyThread_CurrentExceptions(void)
15361536
{
1537-
PyThreadState *tstate = _PyThreadState_GET();
1537+
_PyRuntimeState *runtime = &_PyRuntime;
1538+
PyThreadState *tstate = current_fast_get(runtime);
15381539

15391540
_Py_EnsureTstateNotNULL(tstate);
15401541

@@ -1553,7 +1554,6 @@ _PyThread_CurrentExceptions(void)
15531554
* Because these lists can mutate even when the GIL is held, we
15541555
* need to grab head_mutex for the duration.
15551556
*/
1556-
_PyRuntimeState *runtime = tstate->interp->runtime;
15571557
HEAD_LOCK(runtime);
15581558
PyInterpreterState *i;
15591559
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
@@ -1983,7 +1983,8 @@ _PyObject_CheckCrossInterpreterData(PyObject *obj)
19831983
int
19841984
_PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)
19851985
{
1986-
PyThreadState *tstate = _PyThreadState_GET();
1986+
_PyRuntimeState *runtime = &_PyRuntime;
1987+
PyThreadState *tstate = current_fast_get(runtime);
19871988
#ifdef Py_DEBUG
19881989
// The caller must hold the GIL
19891990
_Py_EnsureTstateNotNULL(tstate);
@@ -2391,8 +2392,9 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
23912392
const PyConfig*
23922393
_Py_GetConfig(void)
23932394
{
2395+
_PyRuntimeState *runtime = &_PyRuntime;
23942396
assert(PyGILState_Check());
2395-
PyThreadState *tstate = _PyThreadState_GET();
2397+
PyThreadState *tstate = current_fast_get(runtime);
23962398
_Py_EnsureTstateNotNULL(tstate);
23972399
return _PyInterpreterState_GetConfig(tstate->interp);
23982400
}

0 commit comments

Comments
 (0)
0