[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: The new patch is fine as it is, but my logic behind using err_flag was the following: err_flag was set solely based on the inspection of return value of fwrite and ferror, without referencing to errno. It is of course true that at the same time errno is set to non-zero in any correct C standard library implementation (err_flag != 0 iff err != 0), but as the patch was originally for circumventing a bug in glibc, I decided to be use that extra flag for the purpose. But I'm still unable to reproduce the glibc bug mentioned by Charles-François : Yes. It seems that the bug in glibc has been fixed. But at least Python 2.7 is now a little bit better guarded against exotic file IO bugs that might emerge in C standard libraries :) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: The test pass with Python 3 which does not use the FILE* API anymore. So you should maybe migrate to Python 3 :-) Yes. I will eventually. But not all the libraries I'm using are migrated yet. -- Added file: http://bugs.python.org/file30317/fileobject-fix5.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Changes by Jaakko Moisio jaakko.moi...@aalto.fi: Added file: http://bugs.python.org/file30266/fileobject-fix4.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: I tried to reply to the review of my last patch but this tracker software itself crashed. Is there anyone who would be interested in the traceback? Anyway, I'll reply here. On 2013/05/15 08:37:29, Charles-François Natali wrote: http://bugs.python.org/review/17976/diff/8158/Objects/fileobject.c File Objects/fileobject.c (right): http://bugs.python.org/review/17976/diff/8158/Objects/fileobject.c#newcode1856 Objects/fileobject.c:1856: if (n2 != n || errno != 0) { Hum, we saw that ferror() could be used to detect the error, so it should be used instead. Also, there's a problem with this patch: it's checking errno too late: for example, it could have been cleared by FILE_END_ALLOW_THREADS or Py_XDECREF in the meantime. Ok. However I must point out that if errno is cleared in the meantime, that also affects PyErr_SetFromErrno. I've submitted another patch where I'm extra careful with errno. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: I tried to reply to the review of my last patch but this tracker software itself crashed. Is there anyone who would be interested in the traceback? Never mind. I found the meta tracker and posted my traceback there. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
New submission from Jaakko Moisio: file.write doesn't sometimes raise IOError when it should, e.g. writing to /dev/full in line buffered mode: jaakko@jm-laptop:~$ python Python 2.7.5+ (2.7:a32a3b79f5e8, May 14 2013, 14:20:11) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. f=open('/dev/full','w',1) f.write('hello\n') Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 28] No space left on device f.close() f=open('/dev/full','w',1) f.write('hello') f.write('\n') f.close() # No IOError! ... The current implementation of file.write relies on comparing the return value of fwrite to the expected number of bytes written to detect errors. I haven't dug deep enough into the C standard to know for sure if fwrite return value == expected should always imply no error, but in my example it clearly doesn't (I assume my glibc and fwrite aren't broken though). However using ferror to detect the error works fine and IOError was raised as expected. Python3 and io module use different implementation where this is no longer an issue. For us still using Python 2.7 I suggest the attached simple patch to fix the issue. -- components: Interpreter Core files: fileobject-fix.patch keywords: patch messages: 189226 nosy: jasujm priority: normal severity: normal status: open title: file.write doesn't raise IOError when it should type: behavior versions: Python 2.7 Added file: http://bugs.python.org/file30258/fileobject-fix.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: Thank you for your comments. I was a little surprised when Jaako says that ferror() is enough to detect this, so I modified Serhiy code to print ferror(), and actually ferror() reports an error for subsequent writes, not for the first one (probably because the error goes unnoticed only when the buffer is in a particular state). Strange. I too modified Serchiy's code and my version of glibc (2.15) set the error flag at the same fwrite call as errno was set: setvbuf 0 0 0 fwrite 5 0 0 fwrite 1 28 1 fwrite 1 28 1 (the last column being the return value of ferror after each fwrite call) I've trusted ferror until now but I'm not an expert on the subject. It's a good point that errno is set by the underlying system call and is thus more reliable. So would checking errno be sufficient (in addition to checking that the lengths agree)? It can only serve to make file_write more robust. -- Added file: http://bugs.python.org/file30260/fileobject-fix2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: Yeah, would you like to write a patch? Yes. It's fileobject-fix3.patch attached to this issue record. -- Added file: http://bugs.python.org/file30262/fileobject-fix3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com