summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-07-12 13:27:49 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-07-12 13:27:49 (GMT)
commitf8c7c20ba5e3e364e7ed2f75ae76df071276b2f6 (patch)
treee17b9d5e04b73348d1ba6c21ca22df8aad1ab37d
parent10c66927742269936ce51b21c790efb8bcbc67dc (diff)
downloadcpython-f8c7c20ba5e3e364e7ed2f75ae76df071276b2f6.zip
cpython-f8c7c20ba5e3e364e7ed2f75ae76df071276b2f6.tar.gz
cpython-f8c7c20ba5e3e364e7ed2f75ae76df071276b2f6.tar.bz2
GC for generator objects.
-rw-r--r--Python/ceval.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 79eb0ad..f42165e 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -121,14 +121,22 @@ gen_new(PyFrameObject *f)
}
gen->gi_frame = f;
gen->gi_running = 0;
+ PyObject_GC_Init(gen);
return (PyObject *)gen;
}
+static int
+gen_traverse(genobject *gen, visitproc visit, void *arg)
+{
+ return visit((PyObject *)gen->gi_frame, arg);
+}
+
static void
gen_dealloc(genobject *gen)
{
+ PyObject_GC_Fini(gen);
Py_DECREF(gen->gi_frame);
- PyObject_DEL(gen);
+ PyObject_Del(gen);
}
static PyObject *
@@ -226,7 +234,7 @@ statichere PyTypeObject gentype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"generator", /* tp_name */
- sizeof(genobject), /* tp_basicsize */
+ sizeof(genobject) + PyGC_HEAD_SIZE, /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)gen_dealloc, /* tp_dealloc */
@@ -244,9 +252,9 @@ statichere PyTypeObject gentype = {
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)gen_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */