Skip to content

Commit

Permalink
[3.12] gh-107916: Save the error code before decoding the filename in…
Browse files Browse the repository at this point in the history
… PyErr_SetFromErrnoWithFilename() etc (GH-107929) (#108205)

gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929)
(cherry picked from commit 80bdebd)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
miss-islington and serhiy-storchaka committed Aug 21, 2023
1 parent 1ce8b92 commit 238c8d2
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 @@ -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 238c8d2

Please sign in to comment.