Commits

Anonymous committed 63ccc64

[svn r67914] Revert patch for #1706039, as it can crash the interpreter.

Comments (0)

Files changed (3)

Lib/test/test_file.py

         finally:
             sys.stdout = save_stdout
 
-    def testReadAfterEOF(self):
-        # Regression test for SF bug #1523853.
-        # Verify read works after hitting EOF
-
-        # Prepare the testfile
-        teststring = "spam"
-        bag = open(TESTFN, "w")
-        bag.write(teststring)
-        bag.close()
-
-        # And buf for readinto
-        buf = array("c", " "*len(teststring))
-
-        # Test for appropriate errors mixing read* and iteration
-        methods = [("readline", ()), ("read",()), ("readlines", ()),
-                   ("readinto", (buf,))]
-
-        for attr in 'r', 'rU':
-            for methodname, args in methods:
-                f = open(TESTFN, "rU")
-                f.seek(0, 2)
-                meth = getattr(f, methodname)
-                meth(*args) # hits EOF
-                try:
-                    # Writing the same file with another file descriptor
-                    append = open(TESTFN, "a+")
-                    append.write(teststring)
-                    append.flush()
-                    append.close()
-                    try:
-                        meth = getattr(f, methodname)
-                        if methodname == 'readlines':
-                            self.failUnlessEqual(meth(*args), [teststring])
-                        elif methodname == 'readinto':
-                            meth(*args)
-                            self.failUnlessEqual(buf.tostring(), teststring)
-                        else:
-                            self.failUnlessEqual(meth(*args), teststring)
-                    except ValueError:
-                        self.fail("read* failed after hitting EOF")
-                finally:
-                    f.close()
 
 def test_main():
     # Historically, these tests have been sloppy about removing TESTFN.
 Core and builtins
 -----------------
 
+- Revert patch for #1706039, as it can crash the interpreter.
+
 - Added test case to ensure attempts to read from a file opened for writing
   fail.
 

Objects/fileobject.c

 			  buffersize - bytesread, f->f_fp, (PyObject *)f);
 		Py_END_ALLOW_THREADS
 		if (chunksize == 0) {
-			if (!PyErr_ExceptionMatches(PyExc_IOError))
+			if (!ferror(f->f_fp))
 				break;
+			clearerr(f->f_fp);
 			/* When in non-blocking mode, data shouldn't
 			 * be discarded if a blocking signal was
 			 * received. That will also happen if
 			 * chunksize != 0, but bytesread < buffersize. */
-			if (bytesread > 0 && BLOCKED_ERRNO(errno)) {
-				PyErr_Clear();
+			if (bytesread > 0 && BLOCKED_ERRNO(errno))
 				break;
-			}
+			PyErr_SetFromErrno(PyExc_IOError);
 			Py_DECREF(v);
 			return NULL;
 		}
 						(PyObject *)f);
 		Py_END_ALLOW_THREADS
 		if (nnow == 0) {
-			if (!PyErr_ExceptionMatches(PyExc_IOError))
+			if (!ferror(f->f_fp))
 				break;
+			PyErr_SetFromErrno(PyExc_IOError);
+			clearerr(f->f_fp);
 			return NULL;
 		}
 		ndone += nnow;
 		}
 		if (nread == 0) {
 			sizehint = 0;
-			if (!PyErr_ExceptionMatches(PyExc_IOError))
+			if (!ferror(f->f_fp))
 				break;
+			PyErr_SetFromErrno(PyExc_IOError);
+			clearerr(f->f_fp);
 		  error:
 			Py_DECREF(list);
 			list = NULL;
 		f->f_buf, bufsize, f->f_fp, (PyObject *)f);
 	Py_END_ALLOW_THREADS
 	if (chunksize == 0) {
-		if (PyErr_ExceptionMatches(PyExc_IOError)) {
+		if (ferror(f->f_fp)) {
+			PyErr_SetFromErrno(PyExc_IOError);
+			clearerr(f->f_fp);
 			drop_readahead(f);
 			return -1;
 		}
 	char *dst = buf;
 	PyFileObject *f = (PyFileObject *)fobj;
 	int newlinetypes, skipnextlf;
-	size_t nread;
 
 	assert(buf != NULL);
 	assert(stream != NULL);
 		errno = ENXIO;	/* What can you do... */
 		return 0;
 	}
-	if (!f->f_univ_newline) {
-		nread = fread(buf, 1, n, stream);
-		if (nread == 0) {
-			if (ferror(stream))
-				PyErr_SetFromErrno(PyExc_IOError);
-			clearerr(stream);
-		}
-		return nread;
-	}
+	if (!f->f_univ_newline)
+		return fread(buf, 1, n, stream);
 	newlinetypes = f->f_newlinetypes;
 	skipnextlf = f->f_skipnextlf;
 	/* Invariant:  n is the number of bytes remaining to be filled
 	 * in the buffer.
 	 */
 	while (n) {
+		size_t nread;
 		int shortread;
 		char *src = dst;
 
 		nread = fread(dst, 1, n, stream);
 		assert(nread <= n);
-		if (nread == 0) {
-			if (ferror(stream)) {
-				clearerr(stream);
-				PyErr_SetFromErrno(PyExc_IOError);
-				return 0;
-			}
-			clearerr(stream);
+		if (nread == 0)
 			break;
-		}
 
 		n -= nread; /* assuming 1 byte out for each in; will adjust */
 		shortread = n != 0;	/* true iff EOF or error */