gh-130595: Keep traceback alive for WITH_EXCEPT_START (#130562)

Keep traceback alive for WITH_EXCEPT_START
This commit is contained in:
Dino Viehland 2025-02-26 10:41:26 -08:00 committed by GitHub
parent 9e474a98af
commit 5c8e8704c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 16 deletions

View file

@ -4426,15 +4426,10 @@
PyObject *exit_func_o = PyStackRef_AsPyObjectBorrow(exit_func);
assert(val_o && PyExceptionInstance_Check(val_o));
exc = PyExceptionInstance_Class(val_o);
tb = PyException_GetTraceback(val_o);
PyObject *original_tb = tb = PyException_GetTraceback(val_o);
if (tb == NULL) {
tb = Py_None;
}
else {
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(tb);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
assert(PyStackRef_LongCheck(lasti));
(void)lasti; // Shut up compiler warning if asserts are off
PyObject *stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
@ -4446,6 +4441,9 @@
if (res_o == NULL) {
JUMP_TO_ERROR();
}
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(original_tb);
stack_pointer = _PyFrame_GetStackPointer(frame);
res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[0] = res;
stack_pointer += 1;