Skip to content

Commit 646e92a

Browse files
committed
Merge branch 'upstream'
2 parents 0d7d38b + 79d996a commit 646e92a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

py/runtime.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,17 +1191,31 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th
11911191

11921192
mp_obj_t dest[3]; // Reserve slot for send() arg
11931193

1194+
// Python instance iterator protocol
11941195
if (send_value == mp_const_none) {
11951196
mp_load_method_maybe(self_in, MP_QSTR___next__, dest);
11961197
if (dest[0] != MP_OBJ_NULL) {
1197-
*ret_val = mp_call_method_n_kw(0, 0, dest);
1198-
return MP_VM_RETURN_YIELD;
1198+
nlr_buf_t nlr;
1199+
if (nlr_push(&nlr) == 0) {
1200+
*ret_val = mp_call_method_n_kw(0, 0, dest);
1201+
nlr_pop();
1202+
return MP_VM_RETURN_YIELD;
1203+
} else {
1204+
*ret_val = nlr.ret_val;
1205+
return MP_VM_RETURN_EXCEPTION;
1206+
}
11991207
}
12001208
}
12011209

1210+
// Either python instance generator protocol, or native object
1211+
// generator protocol.
12021212
if (send_value != MP_OBJ_NULL) {
12031213
mp_load_method(self_in, MP_QSTR_send, dest);
12041214
dest[2] = send_value;
1215+
// TODO: This should have exception wrapping like __next__ case
1216+
// above. Not done right away to think how to optimize native
1217+
// generators better, see:
1218+
// https://github.com/micropython/micropython/issues/2628
12051219
*ret_val = mp_call_method_n_kw(1, 0, dest);
12061220
return MP_VM_RETURN_YIELD;
12071221
}

0 commit comments

Comments
 (0)