@@ -133,7 +133,7 @@ static PyObject *gc_str = NULL;
133
133
#define GEN_HEAD (gcstate , n ) (&(gcstate)->generations[n].head)
134
134
135
135
void
136
- _PyGC_InitializeRuntime (GCState * gcstate )
136
+ _PyGC_InitState (GCState * gcstate )
137
137
{
138
138
gcstate -> enabled = 1 ; /* automatic collection enabled? */
139
139
@@ -159,7 +159,7 @@ _PyGC_InitializeRuntime(GCState *gcstate)
159
159
PyStatus
160
160
_PyGC_Init (PyThreadState * tstate )
161
161
{
162
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
162
+ GCState * gcstate = & tstate -> interp -> gc ;
163
163
if (gcstate -> garbage == NULL ) {
164
164
gcstate -> garbage = PyList_New (0 );
165
165
if (gcstate -> garbage == NULL ) {
@@ -1159,7 +1159,7 @@ collect(PyThreadState *tstate, int generation,
1159
1159
PyGC_Head finalizers ; /* objects with, & reachable from, __del__ */
1160
1160
PyGC_Head * gc ;
1161
1161
_PyTime_t t1 = 0 ; /* initialize to prevent a compiler warning */
1162
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1162
+ GCState * gcstate = & tstate -> interp -> gc ;
1163
1163
1164
1164
if (gcstate -> debug & DEBUG_STATS ) {
1165
1165
PySys_WriteStderr ("gc: collecting generation %d...\n" , generation );
@@ -1324,7 +1324,7 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
1324
1324
assert (!_PyErr_Occurred (tstate ));
1325
1325
1326
1326
/* we may get called very early */
1327
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1327
+ GCState * gcstate = & tstate -> interp -> gc ;
1328
1328
if (gcstate -> callbacks == NULL ) {
1329
1329
return ;
1330
1330
}
@@ -1376,7 +1376,7 @@ collect_with_callback(PyThreadState *tstate, int generation)
1376
1376
static Py_ssize_t
1377
1377
collect_generations (PyThreadState * tstate )
1378
1378
{
1379
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1379
+ GCState * gcstate = & tstate -> interp -> gc ;
1380
1380
/* Find the oldest generation (highest numbered) where the count
1381
1381
* exceeds the threshold. Objects in the that generation and
1382
1382
* generations younger than it will be collected. */
@@ -1410,7 +1410,7 @@ gc_enable_impl(PyObject *module)
1410
1410
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
1411
1411
{
1412
1412
PyThreadState * tstate = _PyThreadState_GET ();
1413
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1413
+ GCState * gcstate = & tstate -> interp -> gc ;
1414
1414
gcstate -> enabled = 1 ;
1415
1415
Py_RETURN_NONE ;
1416
1416
}
@@ -1426,7 +1426,7 @@ gc_disable_impl(PyObject *module)
1426
1426
/*[clinic end generated code: output=97d1030f7aa9d279 input=8c2e5a14e800d83b]*/
1427
1427
{
1428
1428
PyThreadState * tstate = _PyThreadState_GET ();
1429
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1429
+ GCState * gcstate = & tstate -> interp -> gc ;
1430
1430
gcstate -> enabled = 0 ;
1431
1431
Py_RETURN_NONE ;
1432
1432
}
@@ -1442,7 +1442,7 @@ gc_isenabled_impl(PyObject *module)
1442
1442
/*[clinic end generated code: output=1874298331c49130 input=30005e0422373b31]*/
1443
1443
{
1444
1444
PyThreadState * tstate = _PyThreadState_GET ();
1445
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1445
+ GCState * gcstate = & tstate -> interp -> gc ;
1446
1446
return gcstate -> enabled ;
1447
1447
}
1448
1448
@@ -1471,7 +1471,7 @@ gc_collect_impl(PyObject *module, int generation)
1471
1471
return -1 ;
1472
1472
}
1473
1473
1474
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1474
+ GCState * gcstate = & tstate -> interp -> gc ;
1475
1475
Py_ssize_t n ;
1476
1476
if (gcstate -> collecting ) {
1477
1477
/* already collecting, don't do anything */
@@ -1508,7 +1508,7 @@ gc_set_debug_impl(PyObject *module, int flags)
1508
1508
/*[clinic end generated code: output=7c8366575486b228 input=5e5ce15e84fbed15]*/
1509
1509
{
1510
1510
PyThreadState * tstate = _PyThreadState_GET ();
1511
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1511
+ GCState * gcstate = & tstate -> interp -> gc ;
1512
1512
gcstate -> debug = flags ;
1513
1513
Py_RETURN_NONE ;
1514
1514
}
@@ -1524,7 +1524,7 @@ gc_get_debug_impl(PyObject *module)
1524
1524
/*[clinic end generated code: output=91242f3506cd1e50 input=91a101e1c3b98366]*/
1525
1525
{
1526
1526
PyThreadState * tstate = _PyThreadState_GET ();
1527
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1527
+ GCState * gcstate = & tstate -> interp -> gc ;
1528
1528
return gcstate -> debug ;
1529
1529
}
1530
1530
@@ -1538,7 +1538,7 @@ static PyObject *
1538
1538
gc_set_threshold (PyObject * self , PyObject * args )
1539
1539
{
1540
1540
PyThreadState * tstate = _PyThreadState_GET ();
1541
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1541
+ GCState * gcstate = & tstate -> interp -> gc ;
1542
1542
if (!PyArg_ParseTuple (args , "i|ii:set_threshold" ,
1543
1543
& gcstate -> generations [0 ].threshold ,
1544
1544
& gcstate -> generations [1 ].threshold ,
@@ -1562,7 +1562,7 @@ gc_get_threshold_impl(PyObject *module)
1562
1562
/*[clinic end generated code: output=7902bc9f41ecbbd8 input=286d79918034d6e6]*/
1563
1563
{
1564
1564
PyThreadState * tstate = _PyThreadState_GET ();
1565
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1565
+ GCState * gcstate = & tstate -> interp -> gc ;
1566
1566
return Py_BuildValue ("(iii)" ,
1567
1567
gcstate -> generations [0 ].threshold ,
1568
1568
gcstate -> generations [1 ].threshold ,
@@ -1580,7 +1580,7 @@ gc_get_count_impl(PyObject *module)
1580
1580
/*[clinic end generated code: output=354012e67b16398f input=a392794a08251751]*/
1581
1581
{
1582
1582
PyThreadState * tstate = _PyThreadState_GET ();
1583
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1583
+ GCState * gcstate = & tstate -> interp -> gc ;
1584
1584
return Py_BuildValue ("(iii)" ,
1585
1585
gcstate -> generations [0 ].count ,
1586
1586
gcstate -> generations [1 ].count ,
@@ -1630,7 +1630,7 @@ gc_get_referrers(PyObject *self, PyObject *args)
1630
1630
return NULL ;
1631
1631
}
1632
1632
1633
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1633
+ GCState * gcstate = & tstate -> interp -> gc ;
1634
1634
for (i = 0 ; i < NUM_GENERATIONS ; i ++ ) {
1635
1635
if (!(gc_referrers_for (args , GEN_HEAD (gcstate , i ), result ))) {
1636
1636
Py_DECREF (result );
@@ -1695,7 +1695,7 @@ gc_get_objects_impl(PyObject *module, Py_ssize_t generation)
1695
1695
PyThreadState * tstate = _PyThreadState_GET ();
1696
1696
int i ;
1697
1697
PyObject * result ;
1698
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1698
+ GCState * gcstate = & tstate -> interp -> gc ;
1699
1699
1700
1700
result = PyList_New (0 );
1701
1701
if (result == NULL ) {
@@ -1754,7 +1754,7 @@ gc_get_stats_impl(PyObject *module)
1754
1754
1755
1755
/* To get consistent values despite allocations while constructing
1756
1756
the result list, we use a snapshot of the running stats. */
1757
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1757
+ GCState * gcstate = & tstate -> interp -> gc ;
1758
1758
for (i = 0 ; i < NUM_GENERATIONS ; i ++ ) {
1759
1759
stats [i ] = gcstate -> generation_stats [i ];
1760
1760
}
@@ -1827,7 +1827,7 @@ gc_freeze_impl(PyObject *module)
1827
1827
/*[clinic end generated code: output=502159d9cdc4c139 input=b602b16ac5febbe5]*/
1828
1828
{
1829
1829
PyThreadState * tstate = _PyThreadState_GET ();
1830
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1830
+ GCState * gcstate = & tstate -> interp -> gc ;
1831
1831
for (int i = 0 ; i < NUM_GENERATIONS ; ++ i ) {
1832
1832
gc_list_merge (GEN_HEAD (gcstate , i ), & gcstate -> permanent_generation .head );
1833
1833
gcstate -> generations [i ].count = 0 ;
@@ -1848,7 +1848,7 @@ gc_unfreeze_impl(PyObject *module)
1848
1848
/*[clinic end generated code: output=1c15f2043b25e169 input=2dd52b170f4cef6c]*/
1849
1849
{
1850
1850
PyThreadState * tstate = _PyThreadState_GET ();
1851
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1851
+ GCState * gcstate = & tstate -> interp -> gc ;
1852
1852
gc_list_merge (& gcstate -> permanent_generation .head ,
1853
1853
GEN_HEAD (gcstate , NUM_GENERATIONS - 1 ));
1854
1854
Py_RETURN_NONE ;
@@ -1865,7 +1865,7 @@ gc_get_freeze_count_impl(PyObject *module)
1865
1865
/*[clinic end generated code: output=61cbd9f43aa032e1 input=45ffbc65cfe2a6ed]*/
1866
1866
{
1867
1867
PyThreadState * tstate = _PyThreadState_GET ();
1868
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1868
+ GCState * gcstate = & tstate -> interp -> gc ;
1869
1869
return gc_list_size (& gcstate -> permanent_generation .head );
1870
1870
}
1871
1871
@@ -1929,34 +1929,38 @@ static struct PyModuleDef gcmodule = {
1929
1929
PyMODINIT_FUNC
1930
1930
PyInit_gc (void )
1931
1931
{
1932
- PyObject * m ;
1932
+ PyThreadState * tstate = _PyThreadState_GET ();
1933
+ GCState * gcstate = & tstate -> interp -> gc ;
1933
1934
1934
- m = PyModule_Create (& gcmodule );
1935
+ PyObject * m = PyModule_Create (& gcmodule );
1935
1936
1936
1937
if (m == NULL ) {
1937
1938
return NULL ;
1938
1939
}
1939
1940
1940
- GCState * gcstate = & _PyRuntime .gc ;
1941
1941
if (gcstate -> garbage == NULL ) {
1942
1942
gcstate -> garbage = PyList_New (0 );
1943
- if (gcstate -> garbage == NULL )
1943
+ if (gcstate -> garbage == NULL ) {
1944
1944
return NULL ;
1945
+ }
1945
1946
}
1946
1947
Py_INCREF (gcstate -> garbage );
1947
- if (PyModule_AddObject (m , "garbage" , gcstate -> garbage ) < 0 )
1948
+ if (PyModule_AddObject (m , "garbage" , gcstate -> garbage ) < 0 ) {
1948
1949
return NULL ;
1950
+ }
1949
1951
1950
1952
if (gcstate -> callbacks == NULL ) {
1951
1953
gcstate -> callbacks = PyList_New (0 );
1952
- if (gcstate -> callbacks == NULL )
1954
+ if (gcstate -> callbacks == NULL ) {
1953
1955
return NULL ;
1956
+ }
1954
1957
}
1955
1958
Py_INCREF (gcstate -> callbacks );
1956
- if (PyModule_AddObject (m , "callbacks" , gcstate -> callbacks ) < 0 )
1959
+ if (PyModule_AddObject (m , "callbacks" , gcstate -> callbacks ) < 0 ) {
1957
1960
return NULL ;
1961
+ }
1958
1962
1959
- #define ADD_INT (NAME ) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return NULL
1963
+ #define ADD_INT (NAME ) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) { return NULL; }
1960
1964
ADD_INT (DEBUG_STATS );
1961
1965
ADD_INT (DEBUG_COLLECTABLE );
1962
1966
ADD_INT (DEBUG_UNCOLLECTABLE );
@@ -1971,7 +1975,7 @@ Py_ssize_t
1971
1975
PyGC_Collect (void )
1972
1976
{
1973
1977
PyThreadState * tstate = _PyThreadState_GET ();
1974
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
1978
+ GCState * gcstate = & tstate -> interp -> gc ;
1975
1979
1976
1980
if (!gcstate -> enabled ) {
1977
1981
return 0 ;
@@ -2006,7 +2010,7 @@ _PyGC_CollectNoFail(void)
2006
2010
PyThreadState * tstate = _PyThreadState_GET ();
2007
2011
assert (!_PyErr_Occurred (tstate ));
2008
2012
2009
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
2013
+ GCState * gcstate = & tstate -> interp -> gc ;
2010
2014
Py_ssize_t n ;
2011
2015
2012
2016
/* Ideally, this function is only called on interpreter shutdown,
@@ -2029,7 +2033,7 @@ _PyGC_CollectNoFail(void)
2029
2033
void
2030
2034
_PyGC_DumpShutdownStats (PyThreadState * tstate )
2031
2035
{
2032
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
2036
+ GCState * gcstate = & tstate -> interp -> gc ;
2033
2037
if (!(gcstate -> debug & DEBUG_SAVEALL )
2034
2038
&& gcstate -> garbage != NULL && PyList_GET_SIZE (gcstate -> garbage ) > 0 ) {
2035
2039
const char * message ;
@@ -2066,7 +2070,7 @@ _PyGC_DumpShutdownStats(PyThreadState *tstate)
2066
2070
void
2067
2071
_PyGC_Fini (PyThreadState * tstate )
2068
2072
{
2069
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
2073
+ GCState * gcstate = & tstate -> interp -> gc ;
2070
2074
Py_CLEAR (gcstate -> garbage );
2071
2075
Py_CLEAR (gcstate -> callbacks );
2072
2076
}
@@ -2131,7 +2135,7 @@ static PyObject *
2131
2135
_PyObject_GC_Alloc (int use_calloc , size_t basicsize )
2132
2136
{
2133
2137
PyThreadState * tstate = _PyThreadState_GET ();
2134
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
2138
+ GCState * gcstate = & tstate -> interp -> gc ;
2135
2139
if (basicsize > PY_SSIZE_T_MAX - sizeof (PyGC_Head )) {
2136
2140
return _PyErr_NoMemory (tstate );
2137
2141
}
@@ -2230,7 +2234,7 @@ PyObject_GC_Del(void *op)
2230
2234
gc_list_remove (g );
2231
2235
}
2232
2236
PyThreadState * tstate = _PyThreadState_GET ();
2233
- GCState * gcstate = & tstate -> interp -> runtime -> gc ;
2237
+ GCState * gcstate = & tstate -> interp -> gc ;
2234
2238
if (gcstate -> generations [0 ].count > 0 ) {
2235
2239
gcstate -> generations [0 ].count -- ;
2236
2240
}
0 commit comments