aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-02-16 20:39:12 +0000
committerRaymond Hettinger <python@rcn.com>2009-02-16 20:39:12 +0000
commitb21d8109af7b6b3577e566e8c485ec5bcde20181 (patch)
tree03231364353c78206be77c05d95e366bf5df9580 /Modules/itertoolsmodule.c
parentnote functions that are not aliased to PyBytes_ #5280 (diff)
downloadcpython-b21d8109af7b6b3577e566e8c485ec5bcde20181.tar.gz
cpython-b21d8109af7b6b3577e566e8c485ec5bcde20181.tar.bz2
cpython-b21d8109af7b6b3577e566e8c485ec5bcde20181.zip
Add GC support to count() objects. Backport candidate.
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 8a40427f962..7d1791b2e0b 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3271,7 +3271,7 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
cnt == PY_SSIZE_T_MAX && long_cnt != NULL);
/* create countobject structure */
- lz = (countobject *)PyObject_New(countobject, &count_type);
+ lz = (countobject *)type->tp_alloc(type, 0);
if (lz == NULL) {
Py_XDECREF(long_cnt);
return NULL;
@@ -3286,9 +3286,17 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
count_dealloc(countobject *lz)
{
+ PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->long_cnt);
Py_XDECREF(lz->long_step);
- PyObject_Del(lz);
+ Py_TYPE(lz)->tp_free(lz);
+}
+
+count_traverse(countobject *lz, visitproc visit, void *arg)
+{
+ Py_VISIT(lz->long_cnt);
+ Py_VISIT(lz->long_step);
+ return 0;
}
static PyObject *
@@ -3384,9 +3392,10 @@ static PyTypeObject count_type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
count_doc, /* tp_doc */
- 0, /* tp_traverse */
+ (traverseproc)count_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
@@ -3403,6 +3412,7 @@ static PyTypeObject count_type = {
0, /* tp_init */
0, /* tp_alloc */
count_new, /* tp_new */
+ PyObject_GC_Del, /* tp_free */
};