summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-06-26 22:24:51 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-06-26 22:24:51 (GMT)
commite77f2e27987f99683b809981cb1230bfc566e7b7 (patch)
tree230797934676a25a1a61760a09a0b321348b586b /Python
parent0ba70cc3c893f70cc9deb09447277539d7625403 (diff)
downloadcpython-e77f2e27987f99683b809981cb1230bfc566e7b7.zip
cpython-e77f2e27987f99683b809981cb1230bfc566e7b7.tar.gz
cpython-e77f2e27987f99683b809981cb1230bfc566e7b7.tar.bz2
gen_getattr: make the gi_running and gi_frame members discoverable (but
not writable -- too dangerous!) from Python code.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index e4620ab..a73e4d0 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -115,8 +115,8 @@ typedef struct {
PyFrameObject *gi_frame;
- /* True if generator is being executed. */
- int gi_running;
+ /* True if generator is being executed. */
+ int gi_running;
} genobject;
static PyObject *
@@ -207,14 +207,27 @@ gen_getiter(PyObject *gen)
static struct PyMethodDef gen_methods[] = {
{"next", (PyCFunction)gen_next, METH_VARARGS,
- "next() -- get the next value, or raise StopIteration"},
+ "next() -- get the next value, or raise StopIteration"},
{NULL, NULL} /* Sentinel */
};
static PyObject *
gen_getattr(genobject *gen, char *name)
{
- return Py_FindMethod(gen_methods, (PyObject *)gen, name);
+ PyObject *result;
+
+ if (strcmp(name, "gi_frame") == 0) {
+ result = (PyObject *)gen->gi_frame;
+ assert(result != NULL);
+ Py_INCREF(result);
+ }
+ else if (strcmp(name, "gi_running") == 0)
+ result = (PyObject *)PyInt_FromLong((long)gen->gi_running);
+ else if (strcmp(name, "__members__") == 0)
+ result = Py_BuildValue("[ss]", "gi_frame", "gi_running");
+ else
+ result = Py_FindMethod(gen_methods, (PyObject *)gen, name);
+ return result;
}
statichere PyTypeObject gentype = {