Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 18293:0344e4ac70b0 legacy-trunk
gen_getattr: make the gi_running and gi_frame members discoverable (but
not writable -- too dangerous!) from Python code.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 26 Jun 2001 22:24:51 +0000 |
| parents | 6800bcce0455 |
| children | e427afb5637f |
line wrap: on
line diff
--- a/Python/ceval.c Tue Jun 26 22:22:37 2001 +0000 +++ b/Python/ceval.c Tue Jun 26 22:24:51 2001 +0000 @@ -115,8 +115,8 @@ 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 @@ 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 = {
