Merged revisions 68134 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68134 | hirokazu.yamamoto | 2009-01-02 00:45:39 +0900 | 2 lines

  Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
  file with `str' filename on Windows.
........
diff --git a/Misc/NEWS b/Misc/NEWS
index 30668e6..c97daca 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@
 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.
 
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index c36a5de..8579e4e 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -284,10 +284,11 @@
 		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)