Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
PyErr_SetExcFromWindowsErrWithFilename() decode the filename from the
filesystem encoding instead of UTF-8.
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst
index 24ca264..d26e120 100644
--- a/Doc/c-api/exceptions.rst
+++ b/Doc/c-api/exceptions.rst
@@ -219,8 +219,9 @@
Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior that
if *filename* is not *NULL*, it is passed to the constructor of
- :exc:`WindowsError` as a third parameter. *filename* is decoded from UTF-8.
- Availability: Windows.
+ :exc:`WindowsError` as a third parameter. *filename* is decoded from the
+ filesystem encoding (:func:`sys.getfilesystemencoding`). Availability:
+ Windows.
.. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, char *filename)
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 05c5ea8..0f8bcf7 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -202,7 +202,7 @@
int, const char *);
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
int ierr,
- const char *filename /* decoded from UTF-8 */
+ const char *filename, /* decoded from the filesystem encoding */
);
#ifndef Py_LIMITED_API
/* XXX redeclare to use WSTRING */
@@ -215,7 +215,7 @@
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
PyObject *exc,
int ierr,
- const char *filename /* decoded from UTF-8 */
+ const char *filename, /* decoded from the filesystem encoding */
);
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
diff --git a/Misc/NEWS b/Misc/NEWS
index 4fb23c3..7d2085a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -8,6 +8,10 @@
Core and Builtins
-----------------
+- Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
+ PyErr_SetExcFromWindowsErrWithFilename() decode the filename from the
+ filesystem encoding instead of UTF-8.
+
- Issue #10779: PyErr_WarnExplicit() decodes the filename from the filesystem
encoding instead of UTF-8.
diff --git a/Python/errors.c b/Python/errors.c
index d5a6fae..5a9a624 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -515,7 +515,7 @@
int ierr,
const char *filename)
{
- PyObject *name = filename ? PyUnicode_FromString(filename) : NULL;
+ PyObject *name = filename ? PyUnicode_DecodeFSDefault(filename) : NULL;
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc,
ierr,
name);
@@ -552,7 +552,7 @@
int ierr,
const char *filename)
{
- PyObject *name = filename ? PyUnicode_FromString(filename) : NULL;
+ PyObject *name = filename ? PyUnicode_DecodeFSDefault(filename) : NULL;
PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject(
PyExc_WindowsError,
ierr, name);