]> granicus.if.org Git - python/commitdiff
Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Thu, 1 Jan 2009 15:45:39 +0000 (15:45 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Thu, 1 Jan 2009 15:45:39 +0000 (15:45 +0000)
file with `str' filename on Windows.

Misc/NEWS
Modules/_fileio.c

index 8ab8dd2e74fec5152da48b8a7c4ab514ac7c10fa..a0aada94ba34ffc34dd5c8a9abbad881d4f9c5d8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
 Core and Builtins
 -----------------
 
+- Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
+  file with `str' filename on Windows.
+
 - Issue #3680: Reference cycles created through a dict, set or deque iterator
   did not get collected.
 
index ca12822e1db043aca5f8b9e5aa4210b6d7cfd6ea..2dc3d743b85f8279c525df2af15cebcc02d74d4e 100644 (file)
@@ -265,10 +265,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
                Py_END_ALLOW_THREADS
                if (self->fd < 0) {
 #ifdef MS_WINDOWS
-                       PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename);
-#else
-                       PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
+                       if (widename != NULL)
+                               PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename);
+                       else
 #endif
+                               PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
                        goto error;
                }
                if(dircheck(self, name) < 0)