Mercurial > cpython-lru_cache-weakref
diff Modules/arraymodule.c @ 52041:4a3b44c21b4f 3.0
Merged revisions 70203 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r70203 | hirokazu.yamamoto | 2009-03-06 12:04:07 +0900 | 2 lines
Issue #5334: array.fromfile() failed to insert values when EOFError was raised.
Reviewed by Benjamin Peterson.
........
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Fri, 06 Mar 2009 03:19:56 +0000 |
| parents | 87fbbf22adf3 |
| children |
line wrap: on
line diff
--- a/Modules/arraymodule.c Thu Mar 05 15:05:07 2009 +0000 +++ b/Modules/arraymodule.c Fri Mar 06 03:19:56 2009 +0000 @@ -1201,6 +1201,7 @@ PyObject *f, *b, *res; Py_ssize_t itemsize = self->ob_descr->itemsize; Py_ssize_t n, nbytes; + int not_enough_bytes; if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) return NULL; @@ -1222,12 +1223,7 @@ return NULL; } - if (PyBytes_GET_SIZE(b) != nbytes) { - PyErr_SetString(PyExc_EOFError, - "read() didn't return enough bytes"); - Py_DECREF(b); - return NULL; - } + not_enough_bytes = (PyBytes_GET_SIZE(b) != nbytes); args = Py_BuildValue("(O)", b); Py_DECREF(b); @@ -1236,6 +1232,15 @@ res = array_fromstring(self, args); Py_DECREF(args); + if (res == NULL) + return NULL; + + if (not_enough_bytes) { + PyErr_SetString(PyExc_EOFError, + "read() didn't return enough bytes"); + Py_DECREF(res); + return NULL; + } return res; }
