summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-14 23:00:12 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-14 23:00:12 (GMT)
commit9a812cbc899caeb25ab523e904dfac02e4da2999 (patch)
treed54805ed801f969bd6bbfc08640c9dfba076b90c
parentd8b9ae6e8f6d9a562ccdf4700d24c0155979fb4f (diff)
downloadcpython-9a812cbc899caeb25ab523e904dfac02e4da2999.zip
cpython-9a812cbc899caeb25ab523e904dfac02e4da2999.tar.gz
cpython-9a812cbc899caeb25ab523e904dfac02e4da2999.tar.bz2
Issue #13389: Full garbage collection passes now clear the freelists for
list and dict objects. They already cleared other freelists in the interpreter.
-rw-r--r--Doc/c-api/dict.rst7
-rw-r--r--Doc/c-api/list.rst7
-rw-r--r--Include/dictobject.h2
-rw-r--r--Include/listobject.h2
-rw-r--r--Misc/NEWS4
-rw-r--r--Modules/gcmodule.c2
-rw-r--r--Objects/dictobject.c13
-rw-r--r--Objects/listobject.c13
8 files changed, 44 insertions, 6 deletions
diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst
index 6df84e0..ac714a6 100644
--- a/Doc/c-api/dict.rst
+++ b/Doc/c-api/dict.rst
@@ -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
diff --git a/Doc/c-api/list.rst b/Doc/c-api/list.rst
index feb9015..5b263a7 100644
--- a/Doc/c-api/list.rst
+++ b/Doc/c-api/list.rst
@@ -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
diff --git a/Include/dictobject.h b/Include/dictobject.h
index b026785..ed44e20 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -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). */
diff --git a/Include/listobject.h b/Include/listobject.h
index 949b1a3..6fd374b 100644
--- a/Include/listobject.h
+++ b/Include/listobject.h
@@ -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 */
diff --git a/Misc/NEWS b/Misc/NEWS
index 423e29d..082da2a 100644
--- 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
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 6c8ca38..154f136 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -762,6 +762,8 @@ clear_freelists(void)
(void)PyTuple_ClearFreeList();
(void)PyUnicode_ClearFreeList();
(void)PyFloat_ClearFreeList();
+ (void)PyList_ClearFreeList();
+ (void)PyDict_ClearFreeList();
}
static double
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 82735e6..f8f072d 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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 *
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 69a632d..6f1edc5 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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 *