diff options
author | Damien <damien.p.george@gmail.com> | 2013-12-21 18:38:03 +0000 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-12-21 18:38:03 +0000 |
commit | d9d6201b5292308e23b07907350603fafd93f92f (patch) | |
tree | 776400068f989f5095b28573043559b8a5b2cdf0 /py/builtin.c | |
parent | d99b05282d14ceb0163cbcd059aa37bdb415af43 (diff) | |
download | micropython-d9d6201b5292308e23b07907350603fafd93f92f.tar.gz micropython-d9d6201b5292308e23b07907350603fafd93f92f.zip |
py: simplify __next__ method for generators.
Diffstat (limited to 'py/builtin.c')
-rw-r--r-- | py/builtin.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/py/builtin.c b/py/builtin.c index 11e19fdea9..7d2cc72b77 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -11,7 +11,6 @@ #include "obj.h" #include "runtime0.h" #include "runtime.h" -//#include "bc.h" #include "map.h" #include "builtin.h" @@ -293,8 +292,13 @@ mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) { } } -static mp_obj_t mp_builtin_next(mp_obj_t o_in) { - return mp_obj_gen_instance_next(o_in); +static mp_obj_t mp_builtin_next(mp_obj_t o) { + mp_obj_t ret = rt_iternext(o); + if (ret == mp_const_stop_iteration) { + nlr_jump(mp_obj_new_exception(qstr_from_str_static("StopIteration"))); + } else { + return ret; + } } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next); |