mirror of https://github.com/python/cpython
gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929)
This commit is contained in:
parent
acbd3f9c5c
commit
80bdebdd85
|
@ -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`.
|
|
@ -895,10 +895,12 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)
|
||||||
{
|
{
|
||||||
PyObject *name = NULL;
|
PyObject *name = NULL;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
int i = errno;
|
||||||
name = PyUnicode_DecodeFSDefault(filename);
|
name = PyUnicode_DecodeFSDefault(filename);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
errno = i;
|
||||||
}
|
}
|
||||||
PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL);
|
PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL);
|
||||||
Py_XDECREF(name);
|
Py_XDECREF(name);
|
||||||
|
@ -998,6 +1000,9 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename(
|
||||||
{
|
{
|
||||||
PyObject *name = NULL;
|
PyObject *name = NULL;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
if ((DWORD)ierr == 0) {
|
||||||
|
ierr = (int)GetLastError();
|
||||||
|
}
|
||||||
name = PyUnicode_DecodeFSDefault(filename);
|
name = PyUnicode_DecodeFSDefault(filename);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1028,6 +1033,9 @@ PyObject *PyErr_SetFromWindowsErrWithFilename(
|
||||||
{
|
{
|
||||||
PyObject *name = NULL;
|
PyObject *name = NULL;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
if ((DWORD)ierr == 0) {
|
||||||
|
ierr = (int)GetLastError();
|
||||||
|
}
|
||||||
name = PyUnicode_DecodeFSDefault(filename);
|
name = PyUnicode_DecodeFSDefault(filename);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue