From 093ce9cd8c6e4287bffac9d9519d5159d788a008 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 16 Dec 2011 11:24:27 +0100 Subject: Issue #6695: Full garbage collection runs now clear the freelist of set objects. Initial patch by Matthias Troffaes. --- Doc/c-api/set.rst | 7 +++++++ Include/setobject.h | 2 ++ Misc/NEWS | 3 +++ Modules/gcmodule.c | 1 + Objects/setobject.c | 12 ++++++++++-- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst index 66b47c4..5f0ef90 100644 --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -157,3 +157,10 @@ 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. + + +.. c:function:: int PySet_ClearFreeList() + + Clear the free list. Return the total number of freed items. + + .. versionadded:: 3.3 diff --git a/Include/setobject.h b/Include/setobject.h index 6234111..00e5344 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -99,6 +99,8 @@ PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); #ifndef Py_LIMITED_API PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); + +PyAPI_FUNC(int) PySet_ClearFreeList(void); #endif #ifdef __cplusplus diff --git a/Misc/NEWS b/Misc/NEWS index ddf15a0..39e5eca 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Issue #6695: Full garbage collection runs now clear the freelist of set + objects. Initial patch by Matthias Troffaes. + - Fix OSError.__init__ and OSError.__new__ so that each of them can be overriden and take additional arguments (followup to issue #12555). diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 154f136..1876e93 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -764,6 +764,7 @@ clear_freelists(void) (void)PyFloat_ClearFreeList(); (void)PyList_ClearFreeList(); (void)PyDict_ClearFreeList(); + (void)PySet_ClearFreeList(); } static double diff --git a/Objects/setobject.c b/Objects/setobject.c index 5375bd1..a05a97b 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1068,9 +1068,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) { @@ -1078,6 +1079,13 @@ PySet_Fini(void) so = free_list[numfree]; PyObject_GC_Del(so); } + return freelist_size; +} + +void +PySet_Fini(void) +{ + PySet_ClearFreeList(); Py_CLEAR(dummy); Py_CLEAR(emptyfrozenset); } -- cgit v0.12