summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-05-10 17:18:10 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-05-10 17:20:46 +0300
commita7c02c4538bb2b986efb1999e00da4d76345767d (patch)
tree268bc2209dace6083cc2aec5531d69d07bc4deb9 /py/vm.c
parent8fbabab1a80efa8b9c0654f63b2157d8f8299955 (diff)
downloadmicropython-a7c02c4538bb2b986efb1999e00da4d76345767d.tar.gz
micropython-a7c02c4538bb2b986efb1999e00da4d76345767d.zip
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.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/py/vm.c b/py/vm.c
index 38e15eef33..dc228bf0ff 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -1240,13 +1240,17 @@ exception_handler:
code_state->ip -= 1;
#endif
- // 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)) {
- const byte *ip = code_state->ip + 1;
- 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->sp -= 1; // pop the exhausted iterator
- goto outer_dispatch_loop; // continue with dispatch loop
+ 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
+ if (*code_state->ip == MP_BC_FOR_ITER) {
+ const byte *ip = code_state->ip + 1;
+ 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->sp -= 1; // pop the exhausted iterator
+ goto outer_dispatch_loop; // continue with dispatch loop
+ }
+ }
}
#if MICROPY_STACKLESS