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.
This commit is contained in:
Paul Sokolovsky
2015-03-28 01:14:45 +02:00
parent f0a8f21190
commit 7f1c98177b
4 changed files with 38 additions and 3 deletions

View File

@@ -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();
}
}