New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
array.fromfile not checking I/O errors #49645
Comments
At arraymodule.c (line 1258): nread = fread(item + (Py_SIZE(self) - n) * itemsize,
itemsize, n, fp);
if (nread < (size_t)n) {
Py_SIZE(self) -= (n - nread);
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");
return NULL;
} When fread returns 0, ferror should be called to check if it was an EOF |
I attached a path for raising IOErrors in fromfile. I also added a The test opens a file and closes the file with os.close(fd) without |
Ezio, I moved the test to a separate method. Also I couldn't find |
There doesn't seem to be any reason to introduce the |
Ok, I get it, you want f.close() to always succeed, even if the
|
I tried to apply both the patches on the trunk but the tests don't pass. The function I was talking about was test_support.unlink(), but that A few more comments about the latest patch:
|
1&2) I removed the try/except around the import. I have no clue if os I added the try/except because I saw that in other tests in the same
Reliable ways of producing IOErrors are harder to find than I thought. |
Maybe you could create a file without read permission (000) and try |
I just checked. If I don't have read permissions, I am not able to open |
Another try. I have opened a file for writing, and have tried to read >>> fp = open ('xxx', 'w')
>>> fp.read ()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor |
Thanks Aduardo! (I could have sworn I tried that.) I changed the test to |
With the latest patch on Windows Vista against 2.7 I got 12 EOFError errors instead of IOError. |
Sorry for the noise, forgot to rebuild the code. The tests run fine 543 tests ok, except I note that all the output is repeated 6 times, I don't understand this at all. |
Will polish the patch and commit. |
I've committed the new test in py3k (r83030) and 3.1 (r83033), and the full patch in 2.7 (r83031) and 2.6 (r83032). Thank you! |
Regarding:
This is normal, all array tests are run once per array type, and 6 different array types are being tested. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: