From 99a1b20bbf906299a7ea7b871f290dee580a3f18 Mon Sep 17 00:00:00 2001 From: Hirokazu Yamamoto Date: Thu, 1 Jan 2009 15:45:39 +0000 Subject: Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. --- Misc/NEWS | 3 +++ Modules/_fileio.c | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 8ab8dd2..a0aada9 100644 --- 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. diff --git a/Modules/_fileio.c b/Modules/_fileio.c index ca12822..2dc3d74 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -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) -- cgit v0.12