]> granicus.if.org Git - python/commitdiff
Issue #6695: Full garbage collection runs now clear the freelist of set objects.
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 16 Dec 2011 10:24:27 +0000 (11:24 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 16 Dec 2011 10:24:27 +0000 (11:24 +0100)
Initial patch by Matthias Troffaes.

Doc/c-api/set.rst
Include/setobject.h
Misc/NEWS
Modules/gcmodule.c
Objects/setobject.c

index 66b47c4f7182b947b25818b6c50c969fc34a336b..5f0ef90869de3fa5b4c2846b16ba84bfc2b87ad5 100644 (file)
@@ -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
index 623411101d5ba8506a9f07cf8a91042ab4bd3339..00e53449295adb22a5859efb7f4e90bf484af4d4 100644 (file)
@@ -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
index ddf15a0cfc6040c9555b820b2b6a59299b1c44e6..39e5eca5932151279b6cc3d61841d915d9299948 100644 (file)
--- 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).
 
index 154f13623e02da9c7eb63f862f59ac904bfe90cc..1876e93884dda3b2c3499927d01fbcb63739d16b 100644 (file)
@@ -764,6 +764,7 @@ clear_freelists(void)
     (void)PyFloat_ClearFreeList();
     (void)PyList_ClearFreeList();
     (void)PyDict_ClearFreeList();
+    (void)PySet_ClearFreeList();
 }
 
 static double
index 5375bd16cb29ec32ba7f41ae8f3331495326be38..a05a97b233cadb020a807948980878f614e99df0 100644 (file)
@@ -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);
 }