aboutsummaryrefslogtreecommitdiff
path: root/py/stackctrl.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-01 23:30:53 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-07 20:33:00 +0000
commitb4b10fd350852e321624d74983cca286091b55a1 (patch)
tree7ac4aa40d70be0170a61f649e9d73c42faa4ba33 /py/stackctrl.c
parentad2307c92c15f0aa90dbd0741fd2538719d0b5e1 (diff)
py: Put all global state together in state structures.
This patch consolidates all global variables in py/ core into one place, in a global structure. Root pointers are all located together to make GC tracing easier and more efficient.
Diffstat (limited to 'py/stackctrl.c')
-rw-r--r--py/stackctrl.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/py/stackctrl.c b/py/stackctrl.c
index 31336ec69..bf6a815af 100644
--- a/py/stackctrl.c
+++ b/py/stackctrl.c
@@ -24,34 +24,30 @@
* THE SOFTWARE.
*/
+#include "py/mpstate.h"
#include "py/nlr.h"
#include "py/obj.h"
#include "py/stackctrl.h"
-// Stack top at the start of program
-char *stack_top;
-
void mp_stack_ctrl_init(void) {
volatile int stack_dummy;
- stack_top = (char*)&stack_dummy;
+ MP_STATE_VM(stack_top) = (char*)&stack_dummy;
}
mp_uint_t mp_stack_usage(void) {
// Assumes descending stack
volatile int stack_dummy;
- return stack_top - (char*)&stack_dummy;
+ return MP_STATE_VM(stack_top) - (char*)&stack_dummy;
}
#if MICROPY_STACK_CHECK
-static mp_uint_t stack_limit = 10240;
-
void mp_stack_set_limit(mp_uint_t limit) {
- stack_limit = limit;
+ MP_STATE_VM(stack_limit) = limit;
}
void mp_stack_check(void) {
- if (mp_stack_usage() >= stack_limit) {
+ if (mp_stack_usage() >= MP_STATE_VM(stack_limit)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "maximum recursion depth exceeded"));
}
}