Issue #13389: Full garbage collection passes now clear the freelists for
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 14 Nov 2011 23:00:12 +0000 (00:00 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 14 Nov 2011 23:00:12 +0000 (00:00 +0100)
list and dict objects.  They already cleared other freelists in the
interpreter.

Doc/c-api/dict.rst
Doc/c-api/list.rst
Include/dictobject.h
Include/listobject.h
Misc/NEWS
Modules/gcmodule.c
Objects/dictobject.c
Objects/listobject.c

index 6df84e075a5f9b30a998a91ab24a23c9d2cb4f50..ac714a6911349e46c069c0c178f3b32003927fcf 100644 (file)
@@ -209,3 +209,10 @@ Dictionary Objects
           for key, value in seq2:
               if override or key not in a:
                   a[key] = value
+
+
+.. c:function:: int PyDict_ClearFreeList()
+
+   Clear the free list. Return the total number of freed items.
+
+   .. versionadded:: 3.3
index feb9015b6daa7287f11406d5f8f591b1e7a4618b..5b263a7b1cdf04bfce4a3a78f58c09f9c6628e50 100644 (file)
@@ -142,3 +142,10 @@ List Objects
 
    Return a new tuple object containing the contents of *list*; equivalent to
    ``tuple(list)``.
+
+
+.. c:function:: int PyList_ClearFreeList()
+
+   Clear the free list. Return the total number of freed items.
+
+   .. versionadded:: 3.3
index b02678591973fab574bb4267ae13452a53107d5e..ed44e20a23f75be60cf20f0d2628d1dbd3fb31b5 100644 (file)
@@ -129,6 +129,8 @@ PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
 PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
 PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
 PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
+
+PyAPI_FUNC(int) PyDict_ClearFreeList(void);
 #endif
 
 /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
index 949b1a3e3191910637ce1830dcbddb08567a6715..6fd374bb86e72f7d805cb30038e0b71aaf08c10f 100644 (file)
@@ -62,6 +62,8 @@ PyAPI_FUNC(int) PyList_Reverse(PyObject *);
 PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
 #ifndef Py_LIMITED_API
 PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
+
+PyAPI_FUNC(int) PyList_ClearFreeList(void);
 #endif
 
 /* Macro, trading safety for speed */
index 423e29da8fcf4b78dc558c0860cdf456183a43e8..082da2a003ced3a387be6658ef00e61e9fc24333 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #13389: Full garbage collection passes now clear the freelists for
+  list and dict objects.  They already cleared other freelists in the
+  interpreter.
+
 - Issue #13327: Remove the need for an explicit None as the second argument
   to os.utime, os.lutimes, os.futimes, os.futimens, os.futimesat, in
   order to update to the current time. Also added keyword argument
index 6c8ca38d628f2e150f653f4c17c6604cbd9ac6fa..154f13623e02da9c7eb63f862f59ac904bfe90cc 100644 (file)
@@ -762,6 +762,8 @@ clear_freelists(void)
     (void)PyTuple_ClearFreeList();
     (void)PyUnicode_ClearFreeList();
     (void)PyFloat_ClearFreeList();
+    (void)PyList_ClearFreeList();
+    (void)PyDict_ClearFreeList();
 }
 
 static double
index 82735e6753b348373c44b99db927f414dd2cb814..f8f072d4009e9b8f3130c47599434f4b43a58735 100644 (file)
@@ -217,16 +217,23 @@ show_track(void)
 static PyDictObject *free_list[PyDict_MAXFREELIST];
 static int numfree = 0;
 
-void
-PyDict_Fini(void)
+int
+PyDict_ClearFreeList(void)
 {
     PyDictObject *op;
-
+    int ret = numfree;
     while (numfree) {
         op = free_list[--numfree];
         assert(PyDict_CheckExact(op));
         PyObject_GC_Del(op);
     }
+    return ret;
+}
+
+void
+PyDict_Fini(void)
+{
+    PyDict_ClearFreeList();
 }
 
 PyObject *
index 69a632d5289d485385a36dd2b7c5adf5ee366754..6f1edc55d879854799c736257f2e60efc1b969bb 100644 (file)
@@ -97,16 +97,23 @@ show_alloc(void)
 static PyListObject *free_list[PyList_MAXFREELIST];
 static int numfree = 0;
 
-void
-PyList_Fini(void)
+int
+PyList_ClearFreeList(void)
 {
     PyListObject *op;
-
+    int ret = numfree;
     while (numfree) {
         op = free_list[--numfree];
         assert(PyList_CheckExact(op));
         PyObject_GC_Del(op);
     }
+    return ret;
+}
+
+void
+PyList_Fini(void)
+{
+    PyList_ClearFreeList();
 }
 
 PyObject *