diff options
author | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2001-07-12 13:27:25 (GMT) |
---|---|---|
committer | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2001-07-12 13:27:25 (GMT) |
commit | 7eac9b72d45f68d82e1dc463d1050aa86af94709 (patch) | |
tree | 333805f4bae23251cbdb99ea1a65cd7e19dcea7e /Objects | |
parent | 19cd292bbcf1ac3c7e07750ba8c6a3b6b1a479ff (diff) | |
download | cpython-7eac9b72d45f68d82e1dc463d1050aa86af94709.zip cpython-7eac9b72d45f68d82e1dc463d1050aa86af94709.tar.gz cpython-7eac9b72d45f68d82e1dc463d1050aa86af94709.tar.bz2 |
GC for iterator objects.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/iterobject.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 6a11772..c4f4e61 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -18,15 +18,24 @@ PySeqIter_New(PyObject *seq) it->it_index = 0; Py_INCREF(seq); it->it_seq = seq; + PyObject_GC_Init(it); return (PyObject *)it; } static void iter_dealloc(seqiterobject *it) { + PyObject_GC_Fini(it); Py_DECREF(it->it_seq); + it = (seqiterobject *) PyObject_AS_GC(it); PyObject_DEL(it); } +static int +iter_traverse(seqiterobject *it, visitproc visit, void *arg) +{ + return visit(it->it_seq, arg); +} + static PyObject * iter_next(seqiterobject *it, PyObject *args) { @@ -97,7 +106,7 @@ PyTypeObject PySeqIter_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* ob_size */ "iterator", /* tp_name */ - sizeof(seqiterobject), /* tp_basicsize */ + sizeof(seqiterobject) + PyGC_HEAD_SIZE, /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ (destructor)iter_dealloc, /* tp_dealloc */ @@ -115,9 +124,9 @@ PyTypeObject PySeqIter_Type = { 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)iter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -144,16 +153,30 @@ PyCallIter_New(PyObject *callable, PyObject *sentinel) it->it_callable = callable; Py_INCREF(sentinel); it->it_sentinel = sentinel; + PyObject_GC_Init(it); return (PyObject *)it; } static void calliter_dealloc(calliterobject *it) { + PyObject_GC_Fini(it); Py_DECREF(it->it_callable); Py_DECREF(it->it_sentinel); + it = (calliterobject *) PyObject_AS_GC(it); PyObject_DEL(it); } +static int +calliter_traverse(calliterobject *it, visitproc visit, void *arg) +{ + int err; + if ((err = visit(it->it_callable, arg))) + return err; + if ((err = visit(it->it_sentinel, arg))) + return err; + return 0; +} + static PyObject * calliter_next(calliterobject *it, PyObject *args) { @@ -200,7 +223,7 @@ PyTypeObject PyCallIter_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* ob_size */ "callable-iterator", /* tp_name */ - sizeof(calliterobject), /* tp_basicsize */ + sizeof(calliterobject) + PyGC_HEAD_SIZE,/* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ (destructor)calliter_dealloc, /* tp_dealloc */ @@ -218,9 +241,9 @@ PyTypeObject PyCallIter_Type = { 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)calliter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ |