From: Antoine Pitrou Date: Wed, 21 Jul 2010 16:50:52 +0000 (+0000) Subject: Merged revisions 83031 via svnmerge from X-Git-Tag: v2.6.6rc1~113 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea435512eaa8dd3f2a1e1c30e874486d2073038c;p=thirdparty%2FPython%2Fcpython.git Merged revisions 83031 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/release27-maint ................ r83031 | antoine.pitrou | 2010-07-21 18:47:28 +0200 (mer., 21 juil. 2010) | 11 lines Merged revisions 83030 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83030 | antoine.pitrou | 2010-07-21 18:41:31 +0200 (mer., 21 juil. 2010) | 5 lines Issue #5395: check that array.fromfile() re-raises an IOError instead of replacing it with EOFError. (this is only an added test, but 2.x will get a fix too) ........ ................ --- diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 206042f74432..4c870d72906d 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -188,6 +188,17 @@ class BaseTest(unittest.TestCase): f.close() test_support.unlink(test_support.TESTFN) + def test_fromfile_ioerror(self): + # Issue #5395: Check if fromfile raises a proper IOError + # instead of EOFError. + a = array.array(self.typecode) + f = open(test_support.TESTFN, 'wb') + try: + self.assertRaises(IOError, a.fromfile, f, len(self.example)) + finally: + f.close() + test_support.unlink(test_support.TESTFN) + def test_tofromlist(self): a = array.array(self.typecode, 2*self.example) b = array.array(self.typecode) diff --git a/Misc/ACKS b/Misc/ACKS index b6634a789b7b..96523fea6c58 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -328,6 +328,7 @@ Rob Hooft Brian Hooper Randall Hopper Nadav Horesh +Jan Hosang Ken Howard Brad Howes Chih-Hao Huang diff --git a/Misc/NEWS b/Misc/NEWS index c324df36976c..fa9d522b618c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -81,6 +81,10 @@ C-API Library ------- +- Issue #5395: array.fromfile() would raise a spurious EOFError when an + I/O error occurred. Now an IOError is raised instead. Patch by chuck + (Jan Hosang). + - Issue #1555570: email no longer inserts extra blank lines when a \r\n combo crosses an 8192 byte boundary. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index b571fe8254c9..da1bb02e82e0 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1262,8 +1262,14 @@ array_fromfile(arrayobject *self, PyObject *args) PyMem_RESIZE(item, char, Py_SIZE(self)*itemsize); self->ob_item = item; self->allocated = Py_SIZE(self); - PyErr_SetString(PyExc_EOFError, - "not enough items in file"); + if (ferror(fp)) { + PyErr_SetFromErrno(PyExc_IOError); + clearerr(fp); + } + else { + PyErr_SetString(PyExc_EOFError, + "not enough items in file"); + } return NULL; } }