Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 093ce9c

Browse files
committed
Issue #6695: Full garbage collection runs now clear the freelist of set objects.
Initial patch by Matthias Troffaes.
1 parent c144a93 commit 093ce9c

5 files changed

Lines changed: 23 additions & 2 deletions

File tree

Doc/c-api/set.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,10 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
157157
.. c:function:: int PySet_Clear(PyObject *set)
158158
159159
Empty an existing set of all elements.
160+
161+
162+
.. c:function:: int PySet_ClearFreeList()
163+
164+
Clear the free list. Return the total number of freed items.
165+
166+
.. versionadded:: 3.3

Include/setobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key,
9999
PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
100100
#ifndef Py_LIMITED_API
101101
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
102+
103+
PyAPI_FUNC(int) PySet_ClearFreeList(void);
102104
#endif
103105

104106
#ifdef __cplusplus

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #6695: Full garbage collection runs now clear the freelist of set
14+
objects. Initial patch by Matthias Troffaes.
15+
1316
- Fix OSError.__init__ and OSError.__new__ so that each of them can be
1417
overriden and take additional arguments (followup to issue #12555).
1518

Modules/gcmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ clear_freelists(void)
764764
(void)PyFloat_ClearFreeList();
765765
(void)PyList_ClearFreeList();
766766
(void)PyDict_ClearFreeList();
767+
(void)PySet_ClearFreeList();
767768
}
768769

769770
static double

Objects/setobject.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,16 +1068,24 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
10681068
return emptyfrozenset;
10691069
}
10701070

1071-
void
1072-
PySet_Fini(void)
1071+
int
1072+
PySet_ClearFreeList(void)
10731073
{
1074+
int freelist_size = numfree;
10741075
PySetObject *so;
10751076

10761077
while (numfree) {
10771078
numfree--;
10781079
so = free_list[numfree];
10791080
PyObject_GC_Del(so);
10801081
}
1082+
return freelist_size;
1083+
}
1084+
1085+
void
1086+
PySet_Fini(void)
1087+
{
1088+
PySet_ClearFreeList();
10811089
Py_CLEAR(dummy);
10821090
Py_CLEAR(emptyfrozenset);
10831091
}

0 commit comments

Comments
 (0)