bpo-42246: Make sure that f_lasti, and thus f_lineno, is set correctly after raising or reraising an exception (GH-23803)

* Ensure that f_lasti is set correctly after an exception is raised to conform to PEP 626.

* Update importlib

* Add NEWS.
This commit is contained in:
Mark Shannon 2020-12-17 13:55:28 +00:00 committed by GitHub
parent 40125ab325
commit bf353f3c2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 317 additions and 225 deletions

View file

@ -2430,6 +2430,10 @@ main_loop:
}
case TARGET(RERAISE): {
assert(f->f_iblock > 0);
if (oparg) {
f->f_lasti = f->f_blockstack[f->f_iblock-1].b_handler;
}
PyObject *exc = POP();
PyObject *val = POP();
PyObject *tb = POP();
@ -4039,7 +4043,7 @@ exception_unwind:
int handler = b->b_handler;
_PyErr_StackItem *exc_info = tstate->exc_info;
/* Beware, this invalidates all b->b_* fields */
PyFrame_BlockSetup(f, EXCEPT_HANDLER, -1, STACK_LEVEL());
PyFrame_BlockSetup(f, EXCEPT_HANDLER, f->f_lasti, STACK_LEVEL());
PUSH(exc_info->exc_traceback);
PUSH(exc_info->exc_value);
if (exc_info->exc_type != NULL) {