From 987b5016b480eb747158166972cb9e558e7a715b Mon Sep 17 00:00:00 2001 From: "Matthias C. M. Troffaes" Date: Fri, 14 Aug 2009 15:53:09 +0100 Subject: [PATCH 1/3] PyXXX_ClearFreeList calls for dict, set, and list. --- Doc/c-api/dict.rst | 4 ++++ Doc/c-api/list.rst | 4 ++++ Doc/c-api/set.rst | 4 ++++ Include/dictobject.h | 3 +++ Include/listobject.h | 3 +++ Include/setobject.h | 3 +++ Objects/dictobject.c | 12 ++++++++++-- Objects/listobject.c | 11 +++++++++-- Objects/setobject.c | 11 +++++++++-- 9 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst index 6df84e0..417766c 100644 --- a/Doc/c-api/dict.rst +++ b/Doc/c-api/dict.rst @@ -209,3 +209,7 @@ Dictionary Objects 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. diff --git a/Doc/c-api/list.rst b/Doc/c-api/list.rst index feb9015..969193e 100644 --- a/Doc/c-api/list.rst +++ b/Doc/c-api/list.rst @@ -142,3 +142,7 @@ List Objects 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. diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst index 66b47c4..92ee44f 100644 --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -157,3 +157,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes. .. c:function:: 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. diff --git a/Include/dictobject.h b/Include/dictobject.h index b026785..d46101be 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -156,6 +156,9 @@ PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key); 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 diff --git a/Include/listobject.h b/Include/listobject.h index 949b1a3..21bcf05 100644 --- a/Include/listobject.h +++ b/Include/listobject.h @@ -71,6 +71,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *); #define PyList_GET_SIZE(op) Py_SIZE(op) #endif +/* free list api */ +PyAPI_FUNC(int) PyList_ClearFreeList(void); + #ifdef __cplusplus } #endif diff --git a/Include/setobject.h b/Include/setobject.h index 6234111..1a9111c 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -101,6 +101,9 @@ PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); #endif +/* free list api */ +PyAPI_FUNC(int) PySet_ClearFreeList(void); + #ifdef __cplusplus } #endif diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 3fa5cc4..a7259c4 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -217,9 +217,10 @@ show_track(void) 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) { @@ -227,6 +228,13 @@ PyDict_Fini(void) assert(PyDict_CheckExact(op)); PyObject_GC_Del(op); } + return freelist_size; +} + +void +PyDict_Fini(void) +{ + (void)PyDict_ClearFreeList(); } PyObject * diff --git a/Objects/listobject.c b/Objects/listobject.c index dab91db..7a084c5 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -97,9 +97,10 @@ show_alloc(void) 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,6 +108,12 @@ PyList_Fini(void) assert(PyList_CheckExact(op)); PyObject_GC_Del(op); } + return freelist_size; +} + +void +PyList_Fini(void) { + (void)PyList_ClearFreeList(); } PyObject * diff --git a/Objects/setobject.c b/Objects/setobject.c index 2e62518..46a03ff 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1078,9 +1078,10 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return emptyfrozenset; } -void -PySet_Fini(void) +int +PySet_ClearFreeList(void) { + int freelist_size = numfree; PySetObject *so; while (numfree) { @@ -1088,6 +1089,12 @@ PySet_Fini(void) so = free_list[numfree]; PyObject_GC_Del(so); } + return freelist_size; +} + +void +PySet_Fini(void) { + (void)PySet_ClearFreeList(); Py_CLEAR(dummy); Py_CLEAR(emptyfrozenset); } -- 1.7.6