提交 cbf981f3 编写于 作者: J Jeff Epler 提交者: Damien George

py/objgenerator: Check stack before resuming a generator.

This turns a hard crash in a recursive generator into a 'maximum recursion
depth exceeded' exception.
上级 6a693db7
......@@ -32,6 +32,7 @@
#include "py/bc.h"
#include "py/objgenerator.h"
#include "py/objfun.h"
#include "py/stackctrl.h"
/******************************************************************************/
/* generator wrapper */
......@@ -92,6 +93,7 @@ STATIC void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_pri
}
mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val) {
MP_STACK_CHECK();
mp_check_self(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) {
......
......@@ -367,6 +367,7 @@ def run_tests(pyb, tests, args, base_path="."):
skip_tests.add('micropython/heapalloc_iter.py') # requires generators
skip_tests.add('micropython/schedule.py') # native code doesn't check pending events
skip_tests.add('stress/gc_trace.py') # requires yield
skip_tests.add('stress/recursive_gen.py') # requires yield
for test_file in tests:
test_file = test_file.replace('\\', '/')
......
# test deeply recursive generators
def gen():
yield from gen()
try:
list(gen())
except RuntimeError:
print('RuntimeError')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册