diff options
-rwxr-xr-x | Lib/test/test_array.py | 11 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Modules/arraymodule.c | 10 |
4 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 206042f..4c870d7 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) @@ -328,6 +328,7 @@ Rob Hooft Brian Hooper Randall Hopper Nadav Horesh +Jan Hosang Ken Howard Brad Howes Chih-Hao Huang @@ -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 b571fe8..da1bb02 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; } } |