10
10
#include "pycore_pyerrors.h"
11
11
#include "pycore_pylifecycle.h"
12
12
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
13
- #include "pycore_pystate.h" // _PyThreadState_GET()
13
+ #include "pycore_pystate.h"
14
14
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
15
15
#include "pycore_sysmodule.h"
16
16
@@ -391,7 +391,8 @@ PyInterpreterState *
391
391
PyInterpreterState_New (void )
392
392
{
393
393
PyInterpreterState * interp ;
394
- PyThreadState * tstate = _PyThreadState_GET ();
394
+ _PyRuntimeState * runtime = & _PyRuntime ;
395
+ PyThreadState * tstate = current_fast_get (runtime );
395
396
396
397
/* tstate is NULL when Py_InitializeFromConfig() calls
397
398
PyInterpreterState_New() to create the main interpreter. */
@@ -408,7 +409,6 @@ PyInterpreterState_New(void)
408
409
}
409
410
410
411
/* Don't get runtime from tstate since tstate can be NULL. */
411
- _PyRuntimeState * runtime = & _PyRuntime ;
412
412
struct pyinterpreters * interpreters = & runtime -> interpreters ;
413
413
414
414
/* We completely serialize creation of multiple interpreters, since
@@ -556,7 +556,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
556
556
// Use the current Python thread state to call audit hooks and to collect
557
557
// garbage. It can be different than the current Python thread state
558
558
// of 'interp'.
559
- PyThreadState * current_tstate = _PyThreadState_GET ( );
559
+ PyThreadState * current_tstate = current_fast_get ( interp -> runtime );
560
560
561
561
interpreter_clear (interp , current_tstate );
562
562
}
@@ -672,7 +672,7 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime)
672
672
PyInterpreterState *
673
673
PyInterpreterState_Get (void )
674
674
{
675
- PyThreadState * tstate = _PyThreadState_GET ( );
675
+ PyThreadState * tstate = current_fast_get ( & _PyRuntime );
676
676
_Py_EnsureTstateNotNULL (tstate );
677
677
PyInterpreterState * interp = tstate -> interp ;
678
678
if (interp == NULL ) {
@@ -1040,7 +1040,7 @@ PyState_AddModule(PyObject* module, PyModuleDef* def)
1040
1040
return -1 ;
1041
1041
}
1042
1042
1043
- PyThreadState * tstate = _PyThreadState_GET ( );
1043
+ PyThreadState * tstate = current_fast_get ( & _PyRuntime );
1044
1044
PyInterpreterState * interp = tstate -> interp ;
1045
1045
Py_ssize_t index = def -> m_base .m_index ;
1046
1046
if (interp -> modules_by_index &&
@@ -1056,7 +1056,7 @@ PyState_AddModule(PyObject* module, PyModuleDef* def)
1056
1056
int
1057
1057
PyState_RemoveModule (PyModuleDef * def )
1058
1058
{
1059
- PyThreadState * tstate = _PyThreadState_GET ( );
1059
+ PyThreadState * tstate = current_fast_get ( & _PyRuntime );
1060
1060
PyInterpreterState * interp = tstate -> interp ;
1061
1061
1062
1062
if (def -> m_slots ) {
@@ -1282,14 +1282,14 @@ _PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
1282
1282
PyThreadState *
1283
1283
_PyThreadState_UncheckedGet (void )
1284
1284
{
1285
- return _PyThreadState_GET ( );
1285
+ return current_fast_get ( & _PyRuntime );
1286
1286
}
1287
1287
1288
1288
1289
1289
PyThreadState *
1290
1290
PyThreadState_Get (void )
1291
1291
{
1292
- PyThreadState * tstate = _PyThreadState_GET ( );
1292
+ PyThreadState * tstate = current_fast_get ( & _PyRuntime );
1293
1293
_Py_EnsureTstateNotNULL (tstate );
1294
1294
return tstate ;
1295
1295
}
@@ -1355,7 +1355,7 @@ _PyThreadState_GetDict(PyThreadState *tstate)
1355
1355
PyObject *
1356
1356
PyThreadState_GetDict (void )
1357
1357
{
1358
- PyThreadState * tstate = _PyThreadState_GET ( );
1358
+ PyThreadState * tstate = current_fast_get ( & _PyRuntime );
1359
1359
if (tstate == NULL ) {
1360
1360
return NULL ;
1361
1361
}
@@ -1478,7 +1478,8 @@ PyThreadState_Next(PyThreadState *tstate) {
1478
1478
PyObject *
1479
1479
_PyThread_CurrentFrames (void )
1480
1480
{
1481
- PyThreadState * tstate = _PyThreadState_GET ();
1481
+ _PyRuntimeState * runtime = & _PyRuntime ;
1482
+ PyThreadState * tstate = current_fast_get (runtime );
1482
1483
if (_PySys_Audit (tstate , "sys._current_frames" , NULL ) < 0 ) {
1483
1484
return NULL ;
1484
1485
}
@@ -1494,7 +1495,6 @@ _PyThread_CurrentFrames(void)
1494
1495
* Because these lists can mutate even when the GIL is held, we
1495
1496
* need to grab head_mutex for the duration.
1496
1497
*/
1497
- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
1498
1498
HEAD_LOCK (runtime );
1499
1499
PyInterpreterState * i ;
1500
1500
for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
@@ -1534,7 +1534,8 @@ _PyThread_CurrentFrames(void)
1534
1534
PyObject *
1535
1535
_PyThread_CurrentExceptions (void )
1536
1536
{
1537
- PyThreadState * tstate = _PyThreadState_GET ();
1537
+ _PyRuntimeState * runtime = & _PyRuntime ;
1538
+ PyThreadState * tstate = current_fast_get (runtime );
1538
1539
1539
1540
_Py_EnsureTstateNotNULL (tstate );
1540
1541
@@ -1553,7 +1554,6 @@ _PyThread_CurrentExceptions(void)
1553
1554
* Because these lists can mutate even when the GIL is held, we
1554
1555
* need to grab head_mutex for the duration.
1555
1556
*/
1556
- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
1557
1557
HEAD_LOCK (runtime );
1558
1558
PyInterpreterState * i ;
1559
1559
for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
@@ -1983,7 +1983,8 @@ _PyObject_CheckCrossInterpreterData(PyObject *obj)
1983
1983
int
1984
1984
_PyObject_GetCrossInterpreterData (PyObject * obj , _PyCrossInterpreterData * data )
1985
1985
{
1986
- PyThreadState * tstate = _PyThreadState_GET ();
1986
+ _PyRuntimeState * runtime = & _PyRuntime ;
1987
+ PyThreadState * tstate = current_fast_get (runtime );
1987
1988
#ifdef Py_DEBUG
1988
1989
// The caller must hold the GIL
1989
1990
_Py_EnsureTstateNotNULL (tstate );
@@ -2391,8 +2392,9 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
2391
2392
const PyConfig *
2392
2393
_Py_GetConfig (void )
2393
2394
{
2395
+ _PyRuntimeState * runtime = & _PyRuntime ;
2394
2396
assert (PyGILState_Check ());
2395
- PyThreadState * tstate = _PyThreadState_GET ( );
2397
+ PyThreadState * tstate = current_fast_get ( runtime );
2396
2398
_Py_EnsureTstateNotNULL (tstate );
2397
2399
return _PyInterpreterState_GetConfig (tstate -> interp );
2398
2400
}
0 commit comments