comparison 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
comparison
equal deleted inserted replaced
52033:26984450c7e9 52041:4a3b44c21b4f
1199 array_fromfile(arrayobject *self, PyObject *args) 1199 array_fromfile(arrayobject *self, PyObject *args)
1200 { 1200 {
1201 PyObject *f, *b, *res; 1201 PyObject *f, *b, *res;
1202 Py_ssize_t itemsize = self->ob_descr->itemsize; 1202 Py_ssize_t itemsize = self->ob_descr->itemsize;
1203 Py_ssize_t n, nbytes; 1203 Py_ssize_t n, nbytes;
1204 int not_enough_bytes;
1204 1205
1205 if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) 1206 if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n))
1206 return NULL; 1207 return NULL;
1207 1208
1208 nbytes = n * itemsize; 1209 nbytes = n * itemsize;
1220 "read() didn't return bytes"); 1221 "read() didn't return bytes");
1221 Py_DECREF(b); 1222 Py_DECREF(b);
1222 return NULL; 1223 return NULL;
1223 } 1224 }
1224 1225
1225 if (PyBytes_GET_SIZE(b) != nbytes) { 1226 not_enough_bytes = (PyBytes_GET_SIZE(b) != nbytes);
1226 PyErr_SetString(PyExc_EOFError,
1227 "read() didn't return enough bytes");
1228 Py_DECREF(b);
1229 return NULL;
1230 }
1231 1227
1232 args = Py_BuildValue("(O)", b); 1228 args = Py_BuildValue("(O)", b);
1233 Py_DECREF(b); 1229 Py_DECREF(b);
1234 if (args == NULL) 1230 if (args == NULL)
1235 return NULL; 1231 return NULL;
1236 1232
1237 res = array_fromstring(self, args); 1233 res = array_fromstring(self, args);
1238 Py_DECREF(args); 1234 Py_DECREF(args);
1235 if (res == NULL)
1236 return NULL;
1237
1238 if (not_enough_bytes) {
1239 PyErr_SetString(PyExc_EOFError,
1240 "read() didn't return enough bytes");
1241 Py_DECREF(res);
1242 return NULL;
1243 }
1239 1244
1240 return res; 1245 return res;
1241 } 1246 }
1242 1247
1243 PyDoc_STRVAR(fromfile_doc, 1248 PyDoc_STRVAR(fromfile_doc,