diff options
author | Fred Drake <fdrake@acm.org> | 2002-08-09 18:35:52 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2002-08-09 18:35:52 (GMT) |
commit | 72bc456403106c66a551fe046f7355579e17066f (patch) | |
tree | 404799db2b22692e2955203343f1c455c6f47c54 /Python | |
parent | f16c3dc81b33c5eaf977ff850c056f3c05143742 (diff) | |
download | cpython-72bc456403106c66a551fe046f7355579e17066f.zip cpython-72bc456403106c66a551fe046f7355579e17066f.tar.gz cpython-72bc456403106c66a551fe046f7355579e17066f.tar.bz2 |
Add weakref support generator-iterators.
Part of fixing SF bug #591704.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 9df336e..50ea9c3 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -94,6 +94,9 @@ typedef struct { /* True if generator is being executed. */ int gi_running; + + /* List of weak reference. */ + PyObject *gi_weakreflist; } genobject; static PyObject * @@ -106,6 +109,7 @@ gen_new(PyFrameObject *f) } gen->gi_frame = f; gen->gi_running = 0; + gen->gi_weakreflist = NULL; _PyObject_GC_TRACK(gen); return (PyObject *)gen; } @@ -120,6 +124,8 @@ static void gen_dealloc(genobject *gen) { _PyObject_GC_UNTRACK(gen); + if (gen->gi_weakreflist != NULL) + PyObject_ClearWeakRefs((PyObject *) gen); Py_DECREF(gen->gi_frame); PyObject_GC_Del(gen); } @@ -205,7 +211,7 @@ static PyTypeObject gentype = { (traverseproc)gen_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ + offsetof(genobject, gi_weakreflist), /* tp_weaklistoffset */ (getiterfunc)gen_getiter, /* tp_iter */ (iternextfunc)gen_iternext, /* tp_iternext */ 0, /* tp_methods */ |