[Python-checkins] cpython: Issue #13389: Full garbage collection passes now clear the freelists for
antoine.pitrou
python-checkins at python.org
Tue Nov 15 00:10:25 CET 2011
http://hg.python.org/cpython/rev/910986542a75
changeset: 73551:910986542a75
parent: 73549:8f7ab4bf7ad9
user: Antoine Pitrou <solipsis at pitrou.net>
date: Tue Nov 15 00:00:12 2011 +0100
summary:
Issue #13389: Full garbage collection passes now clear the freelists for
list and dict objects. They already cleared other freelists in the
interpreter.
files:
Doc/c-api/dict.rst | 7 +++++++
Doc/c-api/list.rst | 7 +++++++
Include/dictobject.h | 2 ++
Include/listobject.h | 2 ++
Misc/NEWS | 4 ++++
Modules/gcmodule.c | 2 ++
Objects/dictobject.c | 13 ++++++++++---
Objects/listobject.c | 13 ++++++++++---
8 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst
--- a/Doc/c-api/dict.rst
+++ b/Doc/c-api/dict.rst
@@ -209,3 +209,10 @@
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
--- a/Doc/c-api/list.rst
+++ b/Doc/c-api/list.rst
@@ -142,3 +142,10 @@
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
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -129,6 +129,8 @@
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
--- a/Include/listobject.h
+++ b/Include/listobject.h
@@ -62,6 +62,8 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
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
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -762,6 +762,8 @@
(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
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -217,16 +217,23 @@
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
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -97,16 +97,23 @@
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 *
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list