@@ -1176,8 +1176,9 @@ handle_resurrected_objects(PyGC_Head *unreachable, PyGC_Head* still_unreachable,
11761176/* This is the main function. Read this to understand how the
11771177 * collection process works. */
11781178static Py_ssize_t
1179- collect (PyThreadState * tstate , int generation ,
1180- Py_ssize_t * n_collected , Py_ssize_t * n_uncollectable , int nofail )
1179+ gc_collect_main (PyThreadState * tstate , int generation ,
1180+ Py_ssize_t * n_collected , Py_ssize_t * n_uncollectable ,
1181+ int nofail )
11811182{
11821183 int i ;
11831184 Py_ssize_t m = 0 ; /* # objects collected */
@@ -1395,19 +1396,19 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
13951396 * progress callbacks.
13961397 */
13971398static Py_ssize_t
1398- collect_with_callback (PyThreadState * tstate , int generation )
1399+ gc_collect_with_callback (PyThreadState * tstate , int generation )
13991400{
14001401 assert (!_PyErr_Occurred (tstate ));
14011402 Py_ssize_t result , collected , uncollectable ;
14021403 invoke_gc_callback (tstate , "start" , generation , 0 , 0 );
1403- result = collect (tstate , generation , & collected , & uncollectable , 0 );
1404+ result = gc_collect_main (tstate , generation , & collected , & uncollectable , 0 );
14041405 invoke_gc_callback (tstate , "stop" , generation , collected , uncollectable );
14051406 assert (!_PyErr_Occurred (tstate ));
14061407 return result ;
14071408}
14081409
14091410static Py_ssize_t
1410- collect_generations (PyThreadState * tstate )
1411+ gc_collect_generations (PyThreadState * tstate )
14111412{
14121413 GCState * gcstate = & tstate -> interp -> gc ;
14131414 /* Find the oldest generation (highest numbered) where the count
@@ -1455,7 +1456,7 @@ collect_generations(PyThreadState *tstate)
14551456 if (i == NUM_GENERATIONS - 1
14561457 && gcstate -> long_lived_pending < gcstate -> long_lived_total / 4 )
14571458 continue ;
1458- n = collect_with_callback (tstate , i );
1459+ n = gc_collect_with_callback (tstate , i );
14591460 break ;
14601461 }
14611462 }
@@ -1541,7 +1542,7 @@ gc_collect_impl(PyObject *module, int generation)
15411542 }
15421543 else {
15431544 gcstate -> collecting = 1 ;
1544- n = collect_with_callback (tstate , generation );
1545+ n = gc_collect_with_callback (tstate , generation );
15451546 gcstate -> collecting = 0 ;
15461547 }
15471548 return n ;
@@ -2041,7 +2042,7 @@ PyInit_gc(void)
20412042 return m ;
20422043}
20432044
2044- /* API to invoke gc.collect() from C */
2045+ /* Public API to invoke gc.collect() from C */
20452046Py_ssize_t
20462047PyGC_Collect (void )
20472048{
@@ -2061,7 +2062,7 @@ PyGC_Collect(void)
20612062 PyObject * exc , * value , * tb ;
20622063 gcstate -> collecting = 1 ;
20632064 _PyErr_Fetch (tstate , & exc , & value , & tb );
2064- n = collect_with_callback (tstate , NUM_GENERATIONS - 1 );
2065+ n = gc_collect_with_callback (tstate , NUM_GENERATIONS - 1 );
20652066 _PyErr_Restore (tstate , exc , value , tb );
20662067 gcstate -> collecting = 0 ;
20672068 }
@@ -2070,19 +2071,11 @@ PyGC_Collect(void)
20702071}
20712072
20722073Py_ssize_t
2073- _PyGC_CollectIfEnabled ( void )
2074+ _PyGC_CollectNoFail ( PyThreadState * tstate )
20742075{
2075- return PyGC_Collect ();
2076- }
2077-
2078- Py_ssize_t
2079- _PyGC_CollectNoFail (void )
2080- {
2081- PyThreadState * tstate = _PyThreadState_GET ();
20822076 assert (!_PyErr_Occurred (tstate ));
20832077
20842078 GCState * gcstate = & tstate -> interp -> gc ;
2085- Py_ssize_t n ;
20862079
20872080 /* Ideally, this function is only called on interpreter shutdown,
20882081 and therefore not recursively. Unfortunately, when there are daemon
@@ -2091,13 +2084,13 @@ _PyGC_CollectNoFail(void)
20912084 See http://bugs.python.org/issue8713#msg195178 for an example.
20922085 */
20932086 if (gcstate -> collecting ) {
2094- n = 0 ;
2095- }
2096- else {
2097- gcstate -> collecting = 1 ;
2098- n = collect (tstate , NUM_GENERATIONS - 1 , NULL , NULL , 1 );
2099- gcstate -> collecting = 0 ;
2087+ return 0 ;
21002088 }
2089+
2090+ Py_ssize_t n ;
2091+ gcstate -> collecting = 1 ;
2092+ n = gc_collect_main (tstate , NUM_GENERATIONS - 1 , NULL , NULL , 1 );
2093+ gcstate -> collecting = 0 ;
21012094 return n ;
21022095}
21032096
@@ -2240,7 +2233,7 @@ _PyObject_GC_Alloc(int use_calloc, size_t basicsize)
22402233 !_PyErr_Occurred (tstate ))
22412234 {
22422235 gcstate -> collecting = 1 ;
2243- collect_generations (tstate );
2236+ gc_collect_generations (tstate );
22442237 gcstate -> collecting = 0 ;
22452238 }
22462239 PyObject * op = FROM_GC (g );
0 commit comments