File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -224,11 +224,12 @@ PyAPI_FUNC(void) PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator);
224224 * ==========================
225225 */
226226
227- /* C equivalent of gc.collect(). */
227+ /* C equivalent of gc.collect() which ignores the state of gc.enabled . */
228228PyAPI_FUNC (Py_ssize_t ) PyGC_Collect (void );
229229
230230#ifndef Py_LIMITED_API
231231PyAPI_FUNC (Py_ssize_t ) _PyGC_CollectNoFail (void );
232+ PyAPI_FUNC (Py_ssize_t ) _PyGC_CollectIfEnabled (void );
232233#endif
233234
234235/* Test if a type has a GC head */
Original file line number Diff line number Diff line change @@ -1596,6 +1596,15 @@ PyGC_Collect(void)
15961596 return n ;
15971597}
15981598
1599+ Py_ssize_t
1600+ _PyGC_CollectIfEnabled (void )
1601+ {
1602+ if (!enabled )
1603+ return 0 ;
1604+
1605+ return PyGC_Collect ();
1606+ }
1607+
15991608Py_ssize_t
16001609_PyGC_CollectNoFail (void )
16011610{
Original file line number Diff line number Diff line change @@ -600,12 +600,12 @@ Py_FinalizeEx(void)
600600 * XXX but I'm unclear on exactly how that one happens. In any case,
601601 * XXX I haven't seen a real-life report of either of these.
602602 */
603- PyGC_Collect ();
603+ _PyGC_CollectIfEnabled ();
604604#ifdef COUNT_ALLOCS
605605 /* With COUNT_ALLOCS, it helps to run GC multiple times:
606606 each collection might release some types from the type
607607 list, so they become garbage. */
608- while (PyGC_Collect () > 0 )
608+ while (_PyGC_CollectIfEnabled () > 0 )
609609 /* nothing */ ;
610610#endif
611611 /* Destroy all modules */
@@ -632,7 +632,7 @@ Py_FinalizeEx(void)
632632 * XXX Python code getting called.
633633 */
634634#if 0
635- PyGC_Collect ();
635+ _PyGC_CollectIfEnabled ();
636636#endif
637637
638638 /* Disable tracemalloc after all Python objects have been destroyed,
You can’t perform that action at this time.
0 commit comments