summaryrefslogtreecommitdiff
path: root/py/modbuiltins.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-06-29 17:34:34 +1000
committerDamien George <damien@micropython.org>2021-07-15 00:12:41 +1000
commitbb00125aaac8376b8cc4c8f3da2423fcf6dae496 (patch)
tree7a0d5f4de325776418beb96d9f27e46c5793597c /py/modbuiltins.c
parente3825e28e61561427fd5811c1167e05ee3372eb4 (diff)
py: Support single argument to optimised MP_OBJ_STOP_ITERATION.
The MP_OBJ_STOP_ITERATION optimisation is a shortcut for creating a StopIteration() exception object, and means that heap memory does not need to be allocated for the exception (in cases where it can be used). This commit allows this optimised object to take an optional argument (before, it could only have no argument). The commit also adds some new tests to cover corner cases with StopIteration and generators that previously did not work. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/modbuiltins.c')
-rw-r--r--py/modbuiltins.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index c9a49685a..a7e49a1ed 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -322,7 +322,7 @@ STATIC mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) {
if (n_args == 1) {
mp_obj_t ret = mp_iternext_allow_raise(args[0]);
if (ret == MP_OBJ_STOP_ITERATION) {
- mp_raise_type(&mp_type_StopIteration);
+ mp_raise_StopIteration(MP_STATE_THREAD(stop_iteration_arg));
} else {
return ret;
}
@@ -336,7 +336,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_next_obj, 1, 2, mp_builtin_next);
STATIC mp_obj_t mp_builtin_next(mp_obj_t o) {
mp_obj_t ret = mp_iternext_allow_raise(o);
if (ret == MP_OBJ_STOP_ITERATION) {
- mp_raise_type(&mp_type_StopIteration);
+ mp_raise_StopIteration(MP_STATE_THREAD(stop_iteration_arg));
} else {
return ret;
}