]> granicus.if.org Git - python/commitdiff
Apply anonymous SF patch #441229.
authorGuido van Rossum <guido@python.org>
Thu, 9 Aug 2001 18:14:59 +0000 (18:14 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 9 Aug 2001 18:14:59 +0000 (18:14 +0000)
  Previously, f.read() and f.readlines() checked for
  errors on their file object and possibly raised an
  IOError, but f.readline() didn't. This patch makes
  f.readline() behave like the others.

Note that I've added a call to clearerr() since the other calls to
ferror() include that too.

I have no way to test this code. :-)

Objects/fileobject.c

index e01c4398d6d0403a19455d5855bb57138a90bf7c..946d41c22a5a96a53b48bacc23c2c3282c6a6329 100644 (file)
@@ -847,6 +847,12 @@ get_line(PyFileObject *f, int n)
                if (c == '\n')
                        break;
                if (c == EOF) {
+                       if (ferror(fp)) {
+                               PyErr_SetFromErrno(PyExc_IOError);
+                               clearerr(fp);
+                               Py_DECREF(v);
+                               return NULL;
+                       }
                        clearerr(fp);
                        if (PyErr_CheckSignals()) {
                                Py_DECREF(v);