summaryrefslogtreecommitdiffstats
path: root/Objects/genobject.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-26 14:14:20 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-26 14:14:20 (GMT)
commit0cdf9a36ec1b65a655a8af476077c7dd063d87da (patch)
tree0f4068bc8a244ef237f93cb61227dfdf9161f2ea /Objects/genobject.c
parent29604a1b4c09ae6efc47fa0f34412168a34aa7dd (diff)
downloadcpython-0cdf9a36ec1b65a655a8af476077c7dd063d87da.zip
cpython-0cdf9a36ec1b65a655a8af476077c7dd063d87da.tar.gz
cpython-0cdf9a36ec1b65a655a8af476077c7dd063d87da.tar.bz2
#1473257: add generator.gi_code attribute that refers to
the original code object backing the generator. Patch by Collin Winter.
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 4ef710b..3868295 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -11,6 +11,7 @@ static int
gen_traverse(PyGenObject *gen, visitproc visit, void *arg)
{
Py_VISIT((PyObject *)gen->gi_frame);
+ Py_VISIT(gen->gi_code);
return 0;
}
@@ -35,6 +36,7 @@ gen_dealloc(PyGenObject *gen)
_PyObject_GC_UNTRACK(self);
Py_CLEAR(gen->gi_frame);
+ Py_CLEAR(gen->gi_code);
PyObject_GC_Del(gen);
}
@@ -282,6 +284,7 @@ gen_iternext(PyGenObject *gen)
static PyMemberDef gen_memberlist[] = {
{"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), RO},
{"gi_running", T_INT, offsetof(PyGenObject, gi_running), RO},
+ {"gi_code", T_OBJECT, offsetof(PyGenObject, gi_code), RO},
{NULL} /* Sentinel */
};
@@ -352,6 +355,8 @@ PyGen_New(PyFrameObject *f)
return NULL;
}
gen->gi_frame = f;
+ Py_INCREF(f->f_code);
+ gen->gi_code = (PyObject *)(f->f_code);
gen->gi_running = 0;
gen->gi_weakreflist = NULL;
_PyObject_GC_TRACK(gen);