Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec87a13

Browse files
PyErr_NormalizeException doesn't like being called with an exception set
(issues #21677, #21310).
2 parents 915d141 + 76d3f14 commit ec87a13

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

Modules/_io/_iomodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,14 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
470470
if (_PyObject_CallMethodId(result, &PyId_close, NULL) != NULL)
471471
PyErr_Restore(exc, val, tb);
472472
else {
473-
PyObject *val2;
473+
PyObject *exc2, *val2, *tb2;
474+
PyErr_Fetch(&exc2, &val2, &tb2);
474475
PyErr_NormalizeException(&exc, &val, &tb);
475476
Py_XDECREF(exc);
476477
Py_XDECREF(tb);
477-
PyErr_Fetch(&exc, &val2, &tb);
478-
PyErr_NormalizeException(&exc, &val2, &tb);
478+
PyErr_NormalizeException(&exc2, &val2, &tb2);
479479
PyException_SetContext(val2, val);
480-
PyErr_Restore(exc, val2, tb);
480+
PyErr_Restore(exc2, val2, tb2);
481481
}
482482
Py_DECREF(result);
483483
}

Modules/_io/bufferedio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,14 +548,14 @@ buffered_close(buffered *self, PyObject *args)
548548
PyErr_Restore(exc, val, tb);
549549
}
550550
else {
551-
PyObject *val2;
551+
PyObject *exc2, *val2, *tb2;
552+
PyErr_Fetch(&exc2, &val2, &tb2);
552553
PyErr_NormalizeException(&exc, &val, &tb);
553554
Py_DECREF(exc);
554555
Py_XDECREF(tb);
555-
PyErr_Fetch(&exc, &val2, &tb);
556-
PyErr_NormalizeException(&exc, &val2, &tb);
556+
PyErr_NormalizeException(&exc2, &val2, &tb2);
557557
PyException_SetContext(val2, val);
558-
PyErr_Restore(exc, val2, tb);
558+
PyErr_Restore(exc2, val2, tb2);
559559
}
560560
}
561561

Modules/_io/textio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,14 +2619,14 @@ textiowrapper_close(textio *self, PyObject *args)
26192619
PyErr_Restore(exc, val, tb);
26202620
}
26212621
else {
2622-
PyObject *val2;
2622+
PyObject *exc2, *val2, *tb2;
2623+
PyErr_Fetch(&exc2, &val2, &tb2);
26232624
PyErr_NormalizeException(&exc, &val, &tb);
26242625
Py_DECREF(exc);
26252626
Py_XDECREF(tb);
2626-
PyErr_Fetch(&exc, &val2, &tb);
2627-
PyErr_NormalizeException(&exc, &val2, &tb);
2627+
PyErr_NormalizeException(&exc2, &val2, &tb2);
26282628
PyException_SetContext(val2, val);
2629-
PyErr_Restore(exc, val2, tb);
2629+
PyErr_Restore(exc2, val2, tb2);
26302630
}
26312631
}
26322632
return res;

0 commit comments

Comments
 (0)