Index: Include/fileobject.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/fileobject.h,v retrieving revision 2.29 diff -c -r2.29 fileobject.h *** Include/fileobject.h 24 May 2002 15:24:38 -0000 2.29 --- Include/fileobject.h 11 Jul 2002 21:34:17 -0000 *************** *** 16,21 **** --- 16,22 ---- int f_softspace; /* Flag used by 'print' command */ int f_binary; /* Flag which indicates whether the file is open open in binary (1) or test (0) mode */ + PyObject *f_xreadlines; /* Cached xreadlines object */ #ifdef WITH_UNIVERSAL_NEWLINES int f_univ_newline; /* Handle any newline convention */ int f_newlinetypes; /* Types of newlines seen */ Index: Objects/fileobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v retrieving revision 2.164 diff -c -r2.164 fileobject.c *** Objects/fileobject.c 30 Jun 2002 15:26:09 -0000 2.164 --- Objects/fileobject.c 11 Jul 2002 21:34:29 -0000 *************** *** 283,288 **** --- 283,289 ---- } Py_XDECREF(f->f_name); Py_XDECREF(f->f_mode); + Py_XDECREF(f->f_xreadlines); f->ob_type->tp_free((PyObject *)f); } *************** *** 1184,1190 **** if (f->f_fp == NULL) return err_closed(); ! if (!xreadlines_function) { PyObject *xreadlines_module = PyImport_ImportModule("xreadlines"); if(!xreadlines_module) --- 1185,1191 ---- if (f->f_fp == NULL) return err_closed(); ! if (xreadlines_function == NULL) { PyObject *xreadlines_module = PyImport_ImportModule("xreadlines"); if(!xreadlines_module) *************** *** 1196,1202 **** if(!xreadlines_function) return NULL; } ! return PyObject_CallFunction(xreadlines_function, "(O)", f); } static PyObject * --- 1197,1226 ---- if(!xreadlines_function) return NULL; } ! if (f->f_xreadlines == NULL) { ! f->f_xreadlines = ! PyObject_CallFunction(xreadlines_function, "(O)", f); ! } ! Py_INCREF(f->f_xreadlines); ! return f->f_xreadlines; ! } ! ! static PyObject * ! file_next(PyObject *f) ! { ! PyObject* x; ! static iternextfunc xreadlines_next = NULL; ! ! x = ((PyFileObject *)f)->f_xreadlines; ! if (x == NULL) { ! x = file_xreadlines((PyFileObject *)f); ! if (x == NULL) ! return NULL; ! if (xreadlines_next == NULL) { ! xreadlines_next = x->ob_type->tp_iternext; ! } ! } ! return xreadlines_next(x); } static PyObject * *************** *** 1620,1626 **** static PyObject * file_getiter(PyObject *f) { ! return PyObject_CallMethod(f, "xreadlines", ""); } static PyObject * --- 1644,1651 ---- static PyObject * file_getiter(PyObject *f) { ! Py_INCREF(f); ! return f; } static PyObject * *************** *** 1743,1749 **** 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ file_getiter, /* tp_iter */ ! 0, /* tp_iternext */ file_methods, /* tp_methods */ file_memberlist, /* tp_members */ file_getsetlist, /* tp_getset */ --- 1768,1774 ---- 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ file_getiter, /* tp_iter */ ! file_next, /* tp_iternext */ file_methods, /* tp_methods */ file_memberlist, /* tp_members */ file_getsetlist, /* tp_getset */