mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
[3.11] gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929) (GH-108206)
(cherry picked from commit 80bdebdd85
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
be99653080
commit
ed67e60f48
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`.
|
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue