diff options
author | Damien George <damien.p.george@gmail.com> | 2017-01-17 00:10:49 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-01-17 00:10:49 +1100 |
commit | aeb2655073970f8b51572cf033274800a67b23ee (patch) | |
tree | 7b7e6c4ffcb00b43229853b9f010d8a75d3a82af /py | |
parent | 40863fce6fe9fca50f5c31c340d688310a14653b (diff) | |
download | micropython-aeb2655073970f8b51572cf033274800a67b23ee.tar.gz micropython-aeb2655073970f8b51572cf033274800a67b23ee.zip |
py/runtime: Fix handling of throw() when resuming generator.
If GeneratorExit is injected as a throw-value then that should lead to
the close() method being called, if it exists. If close() does not exist
then throw() should not be called, and this patch fixes this.
Diffstat (limited to 'py')
-rw-r--r-- | py/runtime.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/py/runtime.c b/py/runtime.c index a80ddca648..4a51c00b52 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1245,13 +1245,15 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th // We assume one can't "yield" from close() return MP_VM_RETURN_NORMAL; } - } - mp_load_method_maybe(self_in, MP_QSTR_throw, dest); - if (dest[0] != MP_OBJ_NULL) { - *ret_val = mp_call_method_n_kw(1, 0, &throw_value); - // If .throw() method returned, we assume it's value to yield - // - any exception would be thrown with nlr_raise(). - return MP_VM_RETURN_YIELD; + } else { + mp_load_method_maybe(self_in, MP_QSTR_throw, dest); + if (dest[0] != MP_OBJ_NULL) { + dest[2] = throw_value; + *ret_val = mp_call_method_n_kw(1, 0, dest); + // If .throw() method returned, we assume it's value to yield + // - any exception would be thrown with nlr_raise(). + return MP_VM_RETURN_YIELD; + } } // If there's nowhere to throw exception into, then we assume that object // is just incapable to handle it, so any exception thrown into it |