summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-03-06 22:51:36 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-03-06 22:51:36 (GMT)
commita1ca94a1025c3ee1ddf29ebc6d76706f68cf6ea0 (patch)
treeb89886555bbc572ead18bf71f3d4c21fae3225aa /Modules/itertoolsmodule.c
parentad47fa141ca77aee4d68d9f7a37e4bb891ec2682 (diff)
downloadcpython-a1ca94a1025c3ee1ddf29ebc6d76706f68cf6ea0.zip
cpython-a1ca94a1025c3ee1ddf29ebc6d76706f68cf6ea0.tar.gz
cpython-a1ca94a1025c3ee1ddf29ebc6d76706f68cf6ea0.tar.bz2
Issue 2246: itertools grouper object did not participate in GC (should be backported).
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 4d0ad08..259b45a 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -198,7 +198,7 @@ _grouper_create(groupbyobject *parent, PyObject *tgtkey)
{
_grouperobject *igo;
- igo = PyObject_New(_grouperobject, &_grouper_type);
+ igo = PyObject_GC_New(_grouperobject, &_grouper_type);
if (igo == NULL)
return NULL;
igo->parent = (PyObject *)parent;
@@ -206,15 +206,25 @@ _grouper_create(groupbyobject *parent, PyObject *tgtkey)
igo->tgtkey = tgtkey;
Py_INCREF(tgtkey);
+ PyObject_GC_Track(igo);
return (PyObject *)igo;
}
static void
_grouper_dealloc(_grouperobject *igo)
{
+ PyObject_GC_UnTrack(igo);
Py_DECREF(igo->parent);
Py_DECREF(igo->tgtkey);
- PyObject_Del(igo);
+ PyObject_GC_Del(igo);
+}
+
+static int
+_grouper_traverse(_grouperobject *igo, visitproc visit, void *arg)
+{
+ Py_VISIT(igo->parent);
+ Py_VISIT(igo->tgtkey);
+ return 0;
}
static PyObject *
@@ -280,9 +290,9 @@ static PyTypeObject _grouper_type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
0, /* tp_doc */
- 0, /* tp_traverse */
+ (traverseproc)_grouper_traverse,/* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
@@ -299,7 +309,7 @@ static PyTypeObject _grouper_type = {
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
- PyObject_Del, /* tp_free */
+ PyObject_GC_Del, /* tp_free */
};