[Python-Dev] Re: Bug [ 959379 ] Implicit close() should check
for errors
Peter Astrand
astrand at lysator.liu.se
Tue Oct 26 20:48:42 CEST 2004
On Tue, 26 Oct 2004, "Martin v. Löwis" wrote:
> > Yes. Thanks. Here's the new patch. OK to commit?
>
> No. I feel that perror is inappropriate; PySys_WriteStderr
> might be slightly better.
Here's a patch with PySys_WriteStderr:
diff -u -r2.192 fileobject.c
--- Objects/fileobject.c 11 Jun 2004 04:49:03 -0000 2.192
+++ Objects/fileobject.c 26 Oct 2004 18:44:19 -0000
@@ -300,12 +300,15 @@
static void
file_dealloc(PyFileObject *f)
{
+ int sts = 0;
if (f->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) f);
if (f->f_fp != NULL && f->f_close != NULL) {
Py_BEGIN_ALLOW_THREADS
- (*f->f_close)(f->f_fp);
+ sts = (*f->f_close)(f->f_fp);
Py_END_ALLOW_THREADS
+ if (sts == EOF)
+ PySys_WriteStderr("close failed: %s\n", strerror(errno));
}
PyMem_Free(f->f_setbuf);
Py_XDECREF(f->f_name);
>However, it might be that even
> raising an exception has some value.
Is it really possible to raise an exception in response to something
triggered by the GC?
/Peter Åstrand <astrand at lysator.liu.se>
More information about the Python-Dev
mailing list