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 <[email protected]>
  • Loading branch information
serhiy-storchaka authored and miss-islington committed Aug 21, 2023
1 parent f2cc005 commit 1846540
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,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 @@ -1022,6 +1024,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 @@ -1052,6 +1057,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 1846540

Please sign in to comment.