From 7f1c98177bb27a45886fd7e42aa72bef9b1e4a0f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 28 Mar 2015 01:14:45 +0200 Subject: vm: Support strict stackless mode, with proper exception reporting. I.e. in this mode, C stack will never be used to call a Python function, but if there's no free heap for a call, it will be reported as RuntimeError (as expected), not MemoryError. --- py/stackctrl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'py/stackctrl.c') diff --git a/py/stackctrl.c b/py/stackctrl.c index 7d7bbc1be..4c5165372 100644 --- a/py/stackctrl.c +++ b/py/stackctrl.c @@ -27,6 +27,7 @@ #include "py/mpstate.h" #include "py/nlr.h" #include "py/obj.h" +#include "py/runtime.h" #include "py/stackctrl.h" void mp_stack_ctrl_init(void) { @@ -46,10 +47,14 @@ void mp_stack_set_limit(mp_uint_t limit) { MP_STATE_VM(stack_limit) = limit; } +void mp_exc_recursion_depth(void) { + nlr_raise(mp_obj_new_exception_arg1(&mp_type_RuntimeError, + MP_OBJ_NEW_QSTR(MP_QSTR_maximum_space_recursion_space_depth_space_exceeded))); +} + void mp_stack_check(void) { if (mp_stack_usage() >= MP_STATE_VM(stack_limit)) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_RuntimeError, - MP_OBJ_NEW_QSTR(MP_QSTR_maximum_space_recursion_space_depth_space_exceeded))); + mp_exc_recursion_depth(); } } -- cgit v1.2.3