vm: Null pointer test when checking for StopIteration optimizations.
When generator raises exception, it is automatically terminated (by setting its code_state.ip to 0), which interferes with this check. Triggered in particular by CPython's test_pep380.py.
This commit is contained in:
parent
8fbabab1a8
commit
a7c02c4538
6
py/vm.c
6
py/vm.c
@ -1240,14 +1240,18 @@ exception_handler:
|
|||||||
code_state->ip -= 1;
|
code_state->ip -= 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (mp_obj_is_subclass_fast(mp_obj_get_type(nlr.ret_val), &mp_type_StopIteration)) {
|
||||||
|
if (code_state->ip) {
|
||||||
// check if it's a StopIteration within a for block
|
// check if it's a StopIteration within a for block
|
||||||
if (*code_state->ip == MP_BC_FOR_ITER && mp_obj_is_subclass_fast(mp_obj_get_type(nlr.ret_val), &mp_type_StopIteration)) {
|
if (*code_state->ip == MP_BC_FOR_ITER) {
|
||||||
const byte *ip = code_state->ip + 1;
|
const byte *ip = code_state->ip + 1;
|
||||||
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
|
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
|
||||||
code_state->ip = ip + ulab; // jump to after for-block
|
code_state->ip = ip + ulab; // jump to after for-block
|
||||||
code_state->sp -= 1; // pop the exhausted iterator
|
code_state->sp -= 1; // pop the exhausted iterator
|
||||||
goto outer_dispatch_loop; // continue with dispatch loop
|
goto outer_dispatch_loop; // continue with dispatch loop
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if MICROPY_STACKLESS
|
#if MICROPY_STACKLESS
|
||||||
unwind_loop:
|
unwind_loop:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user