Skip to content

Commit c28c79f

Browse files
committed
pythongh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed
1 parent 5dc8c84 commit c28c79f

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

Include/internal/pycore_gc.h

+3
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ extern PyObject *_PyGC_GetReferrers(PyInterpreterState *interp, PyObject *objs);
288288
extern void _PyGC_ClearAllFreeLists(PyInterpreterState *interp);
289289
extern void _Py_ScheduleGC(PyThreadState *tstate);
290290
extern void _Py_RunGC(PyThreadState *tstate);
291+
#ifdef Py_GIL_DISABLED
292+
extern void _PyGC_Clear_DelayedObjects(PyInterpreterState *interp);
293+
#endif
291294

292295
#ifdef __cplusplus
293296
}

Lib/test/support/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ def gc_collect():
785785
gc.collect()
786786
gc.collect()
787787
gc.collect()
788+
gc._collect_delayed_objects()
788789

789790
@contextlib.contextmanager
790791
def disable_gc():

Modules/clinic/gcmodule.c.h

+19-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/gcmodule.c

+19
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ gc_collect_impl(PyObject *module, int generation)
9393
return _PyGC_Collect(tstate, generation, _Py_GC_REASON_MANUAL);
9494
}
9595

96+
/*[clinic input]
97+
gc._collect_delayed_objects
98+
99+
Process delayed free requests by force
100+
101+
[clinic start generated code]*/
102+
103+
static PyObject *
104+
gc__collect_delayed_objects_impl(PyObject *module)
105+
/*[clinic end generated code: output=a016a10f967d4229 input=1064c31903cd9fac]*/
106+
{
107+
#ifdef Py_GIL_DISABLED
108+
PyInterpreterState *interp = _PyInterpreterState_GET();
109+
_PyGC_Clear_DelayedObjects(interp);
110+
#endif
111+
Py_RETURN_NONE;
112+
}
113+
96114
/*[clinic input]
97115
gc.set_debug
98116
@@ -508,6 +526,7 @@ static PyMethodDef GcMethods[] = {
508526
GC_FREEZE_METHODDEF
509527
GC_UNFREEZE_METHODDEF
510528
GC_GET_FREEZE_COUNT_METHODDEF
529+
GC__COLLECT_DELAYED_OBJECTS_METHODDEF
511530
{NULL, NULL} /* Sentinel */
512531
};
513532

Python/gc_free_threading.c

+12
Original file line numberDiff line numberDiff line change
@@ -1758,4 +1758,16 @@ _PyGC_ClearAllFreeLists(PyInterpreterState *interp)
17581758
HEAD_UNLOCK(&_PyRuntime);
17591759
}
17601760

1761+
void
1762+
_PyGC_Clear_DelayedObjects(PyInterpreterState *interp)
1763+
{
1764+
HEAD_LOCK(&_PyRuntime);
1765+
PyThreadState *tstate = interp->threads.head;
1766+
while (tstate != NULL) {
1767+
_PyMem_ProcessDelayed(tstate);
1768+
tstate = (PyThreadState *)tstate->next;
1769+
}
1770+
HEAD_UNLOCK(&_PyRuntime);
1771+
}
1772+
17611773
#endif // Py_GIL_DISABLED

0 commit comments

Comments
 (0)