[Python-Dev] Re: Bug [ 959379 ] Implicit close() should check for errors

Peter Astrand astrand at lysator.liu.se
Sun Nov 7 11:20:47 CET 2004


On Tue, 26 Oct 2004, "Martin v. Löwis" wrote:

> Peter Astrand wrote:
> > +                       PySys_WriteStderr("close failed: %s\n", strerror(errno));
>
> This should use HAVE_STRERROR.

Like this?:

diff -u -r2.192 fileobject.c
--- dist/src/Objects/fileobject.c       11 Jun 2004 04:49:03 -0000      2.192
+++ dist/src/Objects/fileobject.c       7 Nov 2004 10:13:04 -0000
@@ -300,12 +300,19 @@
 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)
+#ifdef HAVE_STRERROR
+                       PySys_WriteStderr("close failed: [Errno %d] %s\n", errno, strerror(errno));
+#else
+                       PySys_WriteStderr("close failed: [Errno %d]\n", errno);
+#endif
        }
        PyMem_Free(f->f_setbuf);
        Py_XDECREF(f->f_name);


/Peter Åstrand <astrand at lysator.liu.se>



More information about the Python-Dev mailing list