diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-01 23:30:53 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-07 20:33:00 +0000 |
commit | b4b10fd350852e321624d74983cca286091b55a1 (patch) | |
tree | 7ac4aa40d70be0170a61f649e9d73c42faa4ba33 /unix/main.c | |
parent | ad2307c92c15f0aa90dbd0741fd2538719d0b5e1 (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 'unix/main.c')
-rw-r--r-- | unix/main.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/unix/main.c b/unix/main.c index 0f1e26f51..3dd71eff8 100644 --- a/unix/main.c +++ b/unix/main.c @@ -35,6 +35,7 @@ #include <sys/types.h> #include <errno.h> +#include "py/mpstate.h" #include "py/nlr.h" #include "py/compile.h" #include "py/parsehelper.h" @@ -61,12 +62,10 @@ long heap_size = 128*1024 * (sizeof(mp_uint_t) / 4); #ifndef _WIN32 #include <signal.h> -STATIC mp_obj_t keyboard_interrupt_obj; - STATIC void sighandler(int signum) { if (signum == SIGINT) { - mp_obj_exception_clear_traceback(keyboard_interrupt_obj); - mp_pending_exception = keyboard_interrupt_obj; + mp_obj_exception_clear_traceback(MP_STATE_VM(keyboard_interrupt_obj)); + MP_STATE_VM(mp_pending_exception) = MP_STATE_VM(keyboard_interrupt_obj); // disable our handler so next we really die struct sigaction sa; sa.sa_handler = SIG_DFL; @@ -336,7 +335,7 @@ int main(int argc, char **argv) { #ifndef _WIN32 // create keyboard interrupt object - keyboard_interrupt_obj = mp_obj_new_exception(&mp_type_KeyboardInterrupt); + MP_STATE_VM(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt); #endif char *home = getenv("HOME"); @@ -448,10 +447,10 @@ int main(int argc, char **argv) { mp_verbose_flag++; } else if (strncmp(argv[a], "-O", 2) == 0) { if (isdigit(argv[a][2])) { - mp_optimise_value = argv[a][2] & 0xf; + MP_STATE_VM(mp_optimise_value) = argv[a][2] & 0xf; } else { - mp_optimise_value = 0; - for (char *p = argv[a] + 1; *p && *p == 'O'; p++, mp_optimise_value++); + MP_STATE_VM(mp_optimise_value) = 0; + for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++); } } else { return usage(argv); |