Skip to content

Commit ae00a5a

Browse files
authored
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.
1 parent cc0dc7e commit ae00a5a

21 files changed

+71
-86
lines changed

Doc/whatsnew/3.9.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,19 @@ Build and C API Changes
672672
the garbage collector respectively. (Contributed by Pablo Galindo in
673673
:issue:`40241`.)
674674

675+
* Remove the following functions from the C API. Call :c:func:`PyGC_Collect`
676+
explicitly to free all free lists.
677+
(Contributed by Victor Stinner in :issue:`40428`.)
678+
679+
* ``PyAsyncGen_ClearFreeLists()``
680+
* ``PyContext_ClearFreeList()``
681+
* ``PyDict_ClearFreeList()``
682+
* ``PyFloat_ClearFreeList()``
683+
* ``PyFrame_ClearFreeList()``
684+
* ``PyList_ClearFreeList()``
685+
* ``PySet_ClearFreeList()``
686+
* ``PyTuple_ClearFreeList()``
687+
675688

676689
Deprecated
677690
==========

Include/context.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
7373
PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
7474

7575

76-
PyAPI_FUNC(int) PyContext_ClearFreeList(void);
77-
78-
7976
#endif /* !Py_LIMITED_API */
8077

8178
#ifdef __cplusplus

Include/cpython/dictobject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
6262
PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
6363
#define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)
6464

65-
PyAPI_FUNC(int) PyDict_ClearFreeList(void);
66-
6765
/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,
6866
the first occurrence of a key wins, if override is 1, the last occurrence
6967
of a key wins, if override is 2, a KeyError with conflicting key as

Include/cpython/frameobject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
7575
PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
7676
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
7777

78-
PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
79-
8078
PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
8179

8280
#ifdef __cplusplus

Include/cpython/listobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ typedef struct {
2626
} PyListObject;
2727

2828
PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
29-
PyAPI_FUNC(int) PyList_ClearFreeList(void);
3029
PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
3130

3231
/* Macro, trading safety for speed */

Include/floatobject.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ PyAPI_FUNC(double) _PyFloat_Unpack2(const unsigned char *p, int le);
100100
PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);
101101
PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);
102102

103-
/* free list api */
104-
PyAPI_FUNC(int) PyFloat_ClearFreeList(void);
105-
106103
PyAPI_FUNC(void) _PyFloat_DebugMallocStats(FILE* out);
107104

108105
/* Format the object based on the format_spec, as defined in PEP 3101

Include/genobject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
9191

9292
PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
9393

94-
int PyAsyncGen_ClearFreeLists(void);
95-
9694
#endif
9795

9896
#undef _PyGenObject_HEAD

Include/internal/pycore_gc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ struct _gc_runtime_state {
163163

164164
PyAPI_FUNC(void) _PyGC_InitState(struct _gc_runtime_state *);
165165

166+
167+
// Functions to clear types free lists
168+
extern void _PyFrame_ClearFreeList(void);
169+
extern void _PyTuple_ClearFreeList(void);
170+
extern void _PyFloat_ClearFreeList(void);
171+
extern void _PyList_ClearFreeList(void);
172+
extern void _PyDict_ClearFreeList(void);
173+
extern void _PyAsyncGen_ClearFreeLists(void);
174+
extern void _PyContext_ClearFreeList(void);
175+
166176
#ifdef __cplusplus
167177
}
168178
#endif

Include/setobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ PyAPI_DATA(PyObject *) _PySet_Dummy;
7070

7171
PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash);
7272
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
73-
PyAPI_FUNC(int) PySet_ClearFreeList(void);
7473

7574
#endif /* Section excluded by Py_LIMITED_API */
7675

Include/tupleobject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
3434
PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
3535
PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
3636

37-
PyAPI_FUNC(int) PyTuple_ClearFreeList(void);
38-
3937
#ifndef Py_LIMITED_API
4038
# define Py_CPYTHON_TUPLEOBJECT_H
4139
# include "cpython/tupleobject.h"

0 commit comments

Comments
 (0)