gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (in Python/) (#102193)

This commit is contained in:
Irit Katriel 2023-02-28 11:50:52 +00:00 committed by GitHub
parent 85b1fc1fc5
commit 4c87537efb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 72 deletions

View file

@ -29,17 +29,14 @@ PyFrameObject *
_PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame)
{
assert(frame->frame_obj == NULL);
PyObject *error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyObject *exc = PyErr_GetRaisedException();
PyFrameObject *f = _PyFrame_New_NoTrack(frame->f_code);
if (f == NULL) {
Py_XDECREF(error_type);
Py_XDECREF(error_value);
Py_XDECREF(error_traceback);
Py_XDECREF(exc);
return NULL;
}
PyErr_Restore(error_type, error_value, error_traceback);
PyErr_SetRaisedException(exc);
if (frame->frame_obj) {
// GH-97002: How did we get into this horrible situation? Most likely,
// allocating f triggered a GC collection, which ran some code that