py/vm: "yield from" didn't handle MP_OBJ_STOP_ITERATION optimization.

E.g. crashed when yielding from already stopped generators.
This commit is contained in:
Paul Sokolovsky 2016-04-28 01:54:23 +03:00
parent d54290f6e2
commit eff85bb1dc
2 changed files with 3 additions and 1 deletions

View File

@ -99,6 +99,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_gen_instance));
mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in);
if (self->code_state.ip == 0) {
// Trying to resume already stopped generator
*ret_val = MP_OBJ_STOP_ITERATION;
return MP_VM_RETURN_NORMAL;
}

View File

@ -1144,7 +1144,8 @@ yield:
if (ret_kind == MP_VM_RETURN_NORMAL) {
// Pop exhausted gen
sp--;
if (ret_value == MP_OBJ_NULL) {
// TODO: When ret_value can be MP_OBJ_NULL here??
if (ret_value == MP_OBJ_NULL || ret_value == MP_OBJ_STOP_ITERATION) {
// Optimize StopIteration
// TODO: get StopIteration's value
PUSH(mp_const_none);