bpo-40428: Remove PyTuple_ClearFreeList() function (GH-19769)
Remove the following function from the C API:
* PyAsyncGen_ClearFreeLists()
* PyContext_ClearFreeList()
* PyDict_ClearFreeList()
* PyFloat_ClearFreeList()
* PyFrame_ClearFreeList()
* PyList_ClearFreeList()
* PySet_ClearFreeList()
* PyTuple_ClearFreeList()
Make these functions private, move them to the internal C API and
change their return type to void.
Call explicitly PyGC_Collect() to free all free lists.
Note: PySet_ClearFreeList() did nothing.
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index b65b8ab..f8648d2 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -955,26 +955,22 @@
return 0;
}
-int
-PyTuple_ClearFreeList(void)
+void
+_PyTuple_ClearFreeList(void)
{
- int freelist_size = 0;
#if PyTuple_MAXSAVESIZE > 0
- int i;
- for (i = 1; i < PyTuple_MAXSAVESIZE; i++) {
- PyTupleObject *p, *q;
- p = free_list[i];
- freelist_size += numfree[i];
+ for (Py_ssize_t i = 1; i < PyTuple_MAXSAVESIZE; i++) {
+ PyTupleObject *p = free_list[i];
free_list[i] = NULL;
numfree[i] = 0;
while (p) {
- q = p;
+ PyTupleObject *q = p;
p = (PyTupleObject *)(p->ob_item[0]);
PyObject_GC_Del(q);
}
}
+ // the empty tuple singleton is only cleared by _PyTuple_Fini()
#endif
- return freelist_size;
}
void
@@ -985,7 +981,7 @@
* rely on the fact that an empty tuple is a singleton. */
Py_CLEAR(free_list[0]);
- (void)PyTuple_ClearFreeList();
+ _PyTuple_ClearFreeList();
#endif
}