@@ -1257,7 +1257,8 @@ static PyObject *
1257
1257
gc_enable_impl (PyObject * module )
1258
1258
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
1259
1259
{
1260
- _PyRuntime .gc .enabled = 1 ;
1260
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1261
+ interp -> gc .enabled = 1 ;
1261
1262
Py_RETURN_NONE ;
1262
1263
}
1263
1264
@@ -1271,7 +1272,8 @@ static PyObject *
1271
1272
gc_disable_impl (PyObject * module )
1272
1273
/*[clinic end generated code: output=97d1030f7aa9d279 input=8c2e5a14e800d83b]*/
1273
1274
{
1274
- _PyRuntime .gc .enabled = 0 ;
1275
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1276
+ interp -> gc .enabled = 0 ;
1275
1277
Py_RETURN_NONE ;
1276
1278
}
1277
1279
@@ -1285,7 +1287,8 @@ static int
1285
1287
gc_isenabled_impl (PyObject * module )
1286
1288
/*[clinic end generated code: output=1874298331c49130 input=30005e0422373b31]*/
1287
1289
{
1288
- return _PyRuntime .gc .enabled ;
1290
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1291
+ return interp -> gc .enabled ;
1289
1292
}
1290
1293
1291
1294
/*[clinic input]
@@ -1312,7 +1315,8 @@ gc_collect_impl(PyObject *module, int generation)
1312
1315
return -1 ;
1313
1316
}
1314
1317
1315
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1318
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1319
+ struct _gc_runtime_state * state = & interp -> gc ;
1316
1320
Py_ssize_t n ;
1317
1321
if (state -> collecting ) {
1318
1322
/* already collecting, don't do anything */
@@ -1348,7 +1352,8 @@ static PyObject *
1348
1352
gc_set_debug_impl (PyObject * module , int flags )
1349
1353
/*[clinic end generated code: output=7c8366575486b228 input=5e5ce15e84fbed15]*/
1350
1354
{
1351
- _PyRuntime .gc .debug = flags ;
1355
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1356
+ interp -> gc .debug = flags ;
1352
1357
1353
1358
Py_RETURN_NONE ;
1354
1359
}
@@ -1363,7 +1368,8 @@ static int
1363
1368
gc_get_debug_impl (PyObject * module )
1364
1369
/*[clinic end generated code: output=91242f3506cd1e50 input=91a101e1c3b98366]*/
1365
1370
{
1366
- return _PyRuntime .gc .debug ;
1371
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1372
+ return interp -> gc .debug ;
1367
1373
}
1368
1374
1369
1375
PyDoc_STRVAR (gc_set_thresh__doc__ ,
@@ -1375,7 +1381,8 @@ PyDoc_STRVAR(gc_set_thresh__doc__,
1375
1381
static PyObject *
1376
1382
gc_set_threshold (PyObject * self , PyObject * args )
1377
1383
{
1378
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1384
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1385
+ struct _gc_runtime_state * state = & interp -> gc ;
1379
1386
if (!PyArg_ParseTuple (args , "i|ii:set_threshold" ,
1380
1387
& state -> generations [0 ].threshold ,
1381
1388
& state -> generations [1 ].threshold ,
@@ -1398,7 +1405,8 @@ static PyObject *
1398
1405
gc_get_threshold_impl (PyObject * module )
1399
1406
/*[clinic end generated code: output=7902bc9f41ecbbd8 input=286d79918034d6e6]*/
1400
1407
{
1401
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1408
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1409
+ struct _gc_runtime_state * state = & interp -> gc ;
1402
1410
return Py_BuildValue ("(iii)" ,
1403
1411
state -> generations [0 ].threshold ,
1404
1412
state -> generations [1 ].threshold ,
@@ -1415,7 +1423,8 @@ static PyObject *
1415
1423
gc_get_count_impl (PyObject * module )
1416
1424
/*[clinic end generated code: output=354012e67b16398f input=a392794a08251751]*/
1417
1425
{
1418
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1426
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1427
+ struct _gc_runtime_state * state = & interp -> gc ;
1419
1428
return Py_BuildValue ("(iii)" ,
1420
1429
state -> generations [0 ].count ,
1421
1430
state -> generations [1 ].count ,
@@ -1462,7 +1471,8 @@ gc_get_referrers(PyObject *self, PyObject *args)
1462
1471
PyObject * result = PyList_New (0 );
1463
1472
if (!result ) return NULL ;
1464
1473
1465
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1474
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1475
+ struct _gc_runtime_state * state = & interp -> gc ;
1466
1476
for (i = 0 ; i < NUM_GENERATIONS ; i ++ ) {
1467
1477
if (!(gc_referrers_for (args , GEN_HEAD (state , i ), result ))) {
1468
1478
Py_DECREF (result );
@@ -1526,7 +1536,8 @@ gc_get_objects_impl(PyObject *module, Py_ssize_t generation)
1526
1536
{
1527
1537
int i ;
1528
1538
PyObject * result ;
1529
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1539
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1540
+ struct _gc_runtime_state * state = & interp -> gc ;
1530
1541
1531
1542
result = PyList_New (0 );
1532
1543
if (result == NULL ) {
@@ -1584,7 +1595,8 @@ gc_get_stats_impl(PyObject *module)
1584
1595
1585
1596
/* To get consistent values despite allocations while constructing
1586
1597
the result list, we use a snapshot of the running stats. */
1587
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1598
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1599
+ struct _gc_runtime_state * state = & interp -> gc ;
1588
1600
for (i = 0 ; i < NUM_GENERATIONS ; i ++ ) {
1589
1601
stats [i ] = state -> generation_stats [i ];
1590
1602
}
@@ -1656,7 +1668,8 @@ static PyObject *
1656
1668
gc_freeze_impl (PyObject * module )
1657
1669
/*[clinic end generated code: output=502159d9cdc4c139 input=b602b16ac5febbe5]*/
1658
1670
{
1659
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1671
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1672
+ struct _gc_runtime_state * state = & interp -> gc ;
1660
1673
for (int i = 0 ; i < NUM_GENERATIONS ; ++ i ) {
1661
1674
gc_list_merge (GEN_HEAD (state , i ), & state -> permanent_generation .head );
1662
1675
state -> generations [i ].count = 0 ;
@@ -1676,7 +1689,8 @@ static PyObject *
1676
1689
gc_unfreeze_impl (PyObject * module )
1677
1690
/*[clinic end generated code: output=1c15f2043b25e169 input=2dd52b170f4cef6c]*/
1678
1691
{
1679
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1692
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1693
+ struct _gc_runtime_state * state = & interp -> gc ;
1680
1694
gc_list_merge (& state -> permanent_generation .head , GEN_HEAD (state , NUM_GENERATIONS - 1 ));
1681
1695
Py_RETURN_NONE ;
1682
1696
}
@@ -1691,7 +1705,8 @@ static Py_ssize_t
1691
1705
gc_get_freeze_count_impl (PyObject * module )
1692
1706
/*[clinic end generated code: output=61cbd9f43aa032e1 input=45ffbc65cfe2a6ed]*/
1693
1707
{
1694
- return gc_list_size (& _PyRuntime .gc .permanent_generation .head );
1708
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1709
+ return gc_list_size (& interp -> gc .permanent_generation .head );
1695
1710
}
1696
1711
1697
1712
@@ -1762,7 +1777,8 @@ PyInit_gc(void)
1762
1777
return NULL ;
1763
1778
}
1764
1779
1765
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1780
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1781
+ struct _gc_runtime_state * state = & interp -> gc ;
1766
1782
if (state -> garbage == NULL ) {
1767
1783
state -> garbage = PyList_New (0 );
1768
1784
if (state -> garbage == NULL )
@@ -1795,7 +1811,8 @@ PyInit_gc(void)
1795
1811
Py_ssize_t
1796
1812
PyGC_Collect (void )
1797
1813
{
1798
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1814
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1815
+ struct _gc_runtime_state * state = & interp -> gc ;
1799
1816
if (!state -> enabled ) {
1800
1817
return 0 ;
1801
1818
}
@@ -1828,7 +1845,8 @@ _PyGC_CollectNoFail(void)
1828
1845
{
1829
1846
assert (!PyErr_Occurred ());
1830
1847
1831
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1848
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1849
+ struct _gc_runtime_state * state = & interp -> gc ;
1832
1850
Py_ssize_t n ;
1833
1851
1834
1852
/* Ideally, this function is only called on interpreter shutdown,
@@ -1849,9 +1867,9 @@ _PyGC_CollectNoFail(void)
1849
1867
}
1850
1868
1851
1869
void
1852
- _PyGC_DumpShutdownStats (_PyRuntimeState * runtime )
1870
+ _PyGC_DumpShutdownStats (PyInterpreterState * interp )
1853
1871
{
1854
- struct _gc_runtime_state * state = & runtime -> gc ;
1872
+ struct _gc_runtime_state * state = & interp -> gc ;
1855
1873
if (!(state -> debug & DEBUG_SAVEALL )
1856
1874
&& state -> garbage != NULL && PyList_GET_SIZE (state -> garbage ) > 0 ) {
1857
1875
const char * message ;
@@ -1886,9 +1904,9 @@ _PyGC_DumpShutdownStats(_PyRuntimeState *runtime)
1886
1904
}
1887
1905
1888
1906
void
1889
- _PyGC_Fini (_PyRuntimeState * runtime )
1907
+ _PyGC_Fini (PyInterpreterState * interp )
1890
1908
{
1891
- struct _gc_runtime_state * state = & runtime -> gc ;
1909
+ struct _gc_runtime_state * state = & interp -> gc ;
1892
1910
Py_CLEAR (state -> garbage );
1893
1911
Py_CLEAR (state -> callbacks );
1894
1912
}
@@ -1930,7 +1948,8 @@ PyObject_GC_UnTrack(void *op_raw)
1930
1948
static PyObject *
1931
1949
_PyObject_GC_Alloc (int use_calloc , size_t basicsize )
1932
1950
{
1933
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
1951
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
1952
+ struct _gc_runtime_state * state = & interp -> gc ;
1934
1953
PyObject * op ;
1935
1954
PyGC_Head * g ;
1936
1955
size_t size ;
@@ -2023,7 +2042,8 @@ PyObject_GC_Del(void *op)
2023
2042
if (_PyObject_GC_IS_TRACKED (op )) {
2024
2043
gc_list_remove (g );
2025
2044
}
2026
- struct _gc_runtime_state * state = & _PyRuntime .gc ;
2045
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
2046
+ struct _gc_runtime_state * state = & interp -> gc ;
2027
2047
if (state -> generations [0 ].count > 0 ) {
2028
2048
state -> generations [0 ].count -- ;
2029
2049
}
0 commit comments