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
  • Loading branch information
serhiy-storchaka committed Aug 14, 2023
1 parent b986253 commit ad2547a
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 @@ -895,10 +895,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 @@ -998,6 +1000,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 @@ -1028,6 +1033,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 ad2547a

Please sign in to comment.