Index: Include/dictobject.h =================================================================== --- Include/dictobject.h (revision 74415) +++ Include/dictobject.h (working copy) @@ -152,6 +152,9 @@ PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key); +/* free list api */ +PyAPI_FUNC(int) PyDict_ClearFreeList(void); + #ifdef __cplusplus } #endif Index: Include/listobject.h =================================================================== --- Include/listobject.h (revision 74415) +++ Include/listobject.h (working copy) @@ -65,6 +65,9 @@ #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) #define PyList_GET_SIZE(op) Py_SIZE(op) +/* free list api */ +PyAPI_FUNC(int) PyList_ClearFreeList(void); + #ifdef __cplusplus } #endif Index: Include/setobject.h =================================================================== --- Include/setobject.h (revision 74415) +++ Include/setobject.h (working copy) @@ -93,6 +93,9 @@ PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); +/* free list api */ +PyAPI_FUNC(int) PySet_ClearFreeList(void); + #ifdef __cplusplus } #endif Index: Objects/dictobject.c =================================================================== --- Objects/dictobject.c (revision 74415) +++ Objects/dictobject.c (working copy) @@ -226,9 +226,10 @@ static PyDictObject *free_list[PyDict_MAXFREELIST]; static int numfree = 0; -void -PyDict_Fini(void) +int +PyDict_ClearFreeList(void) { + int freelist_size = numfree; PyDictObject *op; while (numfree) { @@ -236,8 +237,15 @@ assert(PyDict_CheckExact(op)); PyObject_GC_Del(op); } + return freelist_size; } +void +PyDict_Fini(void) +{ + (void)PyDict_ClearFreeList(); +} + PyObject * PyDict_New(void) { Index: Objects/listobject.c =================================================================== --- Objects/listobject.c (revision 74415) +++ Objects/listobject.c (working copy) @@ -97,9 +97,10 @@ static PyListObject *free_list[PyList_MAXFREELIST]; static int numfree = 0; -void -PyList_Fini(void) +int +PyList_ClearFreeList(void) { + int freelist_size = numfree; PyListObject *op; while (numfree) { @@ -107,8 +108,14 @@ assert(PyList_CheckExact(op)); PyObject_GC_Del(op); } + return freelist_size; } +void +PyList_Fini(void) { + (void)PyList_ClearFreeList(); +} + PyObject * PyList_New(Py_ssize_t size) { Index: Objects/setobject.c =================================================================== --- Objects/setobject.c (revision 74415) +++ Objects/setobject.c (working copy) @@ -1072,9 +1072,10 @@ return emptyfrozenset; } -void -PySet_Fini(void) +int +PySet_ClearFreeList(void) { + int freelist_size = numfree; PySetObject *so; while (numfree) { @@ -1082,6 +1083,12 @@ so = free_list[numfree]; PyObject_GC_Del(so); } + return freelist_size; +} + +void +PySet_Fini(void) { + (void)PySet_ClearFreeList(); Py_CLEAR(dummy); Py_CLEAR(emptyfrozenset); } Index: Doc/c-api/list.rst =================================================================== --- Doc/c-api/list.rst (revision 74415) +++ Doc/c-api/list.rst (working copy) @@ -145,3 +145,7 @@ Return a new tuple object containing the contents of *list*; equivalent to ``tuple(list)``. + +.. cfunction:: int PyList_ClearFreeList(void) + + Clear the free list. Return the total number of freed items. Index: Doc/c-api/set.rst =================================================================== --- Doc/c-api/set.rst (revision 74415) +++ Doc/c-api/set.rst (working copy) @@ -157,3 +157,7 @@ .. cfunction:: int PySet_Clear(PyObject *set) Empty an existing set of all elements. + +.. cfunction:: int PySet_ClearFreeList(void) + + Clear the free list. Return the total number of freed items. Index: Doc/c-api/dict.rst =================================================================== --- Doc/c-api/dict.rst (revision 74415) +++ Doc/c-api/dict.rst (working copy) @@ -216,3 +216,7 @@ for key, value in seq2: if override or key not in a: a[key] = value + +.. cfunction:: int PyDict_ClearFreeList(void) + + Clear the free list. Return the total number of freed items.