Skip to content

Commit

Permalink
pythongh-107916: Save the error code before decoding the filename in …
Browse files Browse the repository at this point in the history
…PyErr_SetFromErrnoWithFilename() etc (pythonGH-107929)

(cherry picked from commit 80bdebd)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
serhiy-storchaka authored and miss-islington committed Aug 21, 2023
1 parent be99653 commit 79cd603
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
@@ -0,0 +1,4 @@
C API functions :c:func:`PyErr_SetFromErrnoWithFilename`,
:c:func:`PyErr_SetExcFromWindowsErrWithFilename` and
:c:func:`PyErr_SetFromWindowsErrWithFilename` save now the error code before
calling :c:func:`PyUnicode_DecodeFSDefault`.
8 changes: 8 additions & 0 deletions Python/errors.c
Expand Up @@ -856,10 +856,12 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)
{
PyObject *name = NULL;
if (filename) {
int i = errno;
name = PyUnicode_DecodeFSDefault(filename);
if (name == NULL) {
return NULL;
}
errno = i;
}
PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL);
Py_XDECREF(name);
Expand Down Expand Up @@ -959,6 +961,9 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename(
{
PyObject *name = NULL;
if (filename) {
if ((DWORD)ierr == 0) {
ierr = (int)GetLastError();
}
name = PyUnicode_DecodeFSDefault(filename);
if (name == NULL) {
return NULL;
Expand Down Expand Up @@ -989,6 +994,9 @@ PyObject *PyErr_SetFromWindowsErrWithFilename(
{
PyObject *name = NULL;
if (filename) {
if ((DWORD)ierr == 0) {
ierr = (int)GetLastError();
}
name = PyUnicode_DecodeFSDefault(filename);
if (name == NULL) {
return NULL;
Expand Down

0 comments on commit 79cd603

Please sign in to comment.