Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92be939

Browse files
author
Victor Stinner
committed
Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
PyErr_SetExcFromWindowsErrWithFilename() decode the filename from the filesystem encoding instead of UTF-8.
1 parent 83098a4 commit 92be939

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

Doc/c-api/exceptions.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ in various ways. There is a separate error indicator for each thread.
219219
220220
Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior that
221221
if *filename* is not *NULL*, it is passed to the constructor of
222-
:exc:`WindowsError` as a third parameter. *filename* is decoded from UTF-8.
223-
Availability: Windows.
222+
:exc:`WindowsError` as a third parameter. *filename* is decoded from the
223+
filesystem encoding (:func:`sys.getfilesystemencoding`). Availability:
224+
Windows.
224225
225226
226227
.. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, char *filename)

Include/pyerrors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
202202
int, const char *);
203203
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
204204
int ierr,
205-
const char *filename /* decoded from UTF-8 */
205+
const char *filename, /* decoded from the filesystem encoding */
206206
);
207207
#ifndef Py_LIMITED_API
208208
/* XXX redeclare to use WSTRING */
@@ -215,7 +215,7 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
215215
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
216216
PyObject *exc,
217217
int ierr,
218-
const char *filename /* decoded from UTF-8 */
218+
const char *filename, /* decoded from the filesystem encoding */
219219
);
220220
#ifndef Py_LIMITED_API
221221
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ What's New in Python 3.2 Release Candidate 1
88
Core and Builtins
99
-----------------
1010

11+
- Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
12+
PyErr_SetExcFromWindowsErrWithFilename() decode the filename from the
13+
filesystem encoding instead of UTF-8.
14+
1115
- Issue #10779: PyErr_WarnExplicit() decodes the filename from the filesystem
1216
encoding instead of UTF-8.
1317

Python/errors.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename(
515515
int ierr,
516516
const char *filename)
517517
{
518-
PyObject *name = filename ? PyUnicode_FromString(filename) : NULL;
518+
PyObject *name = filename ? PyUnicode_DecodeFSDefault(filename) : NULL;
519519
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc,
520520
ierr,
521521
name);
@@ -552,7 +552,7 @@ PyObject *PyErr_SetFromWindowsErrWithFilename(
552552
int ierr,
553553
const char *filename)
554554
{
555-
PyObject *name = filename ? PyUnicode_FromString(filename) : NULL;
555+
PyObject *name = filename ? PyUnicode_DecodeFSDefault(filename) : NULL;
556556
PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject(
557557
PyExc_WindowsError,
558558
ierr, name);

0 commit comments

Comments
 (0)