diff options
author | Damien George <damien.p.george@gmail.com> | 2015-05-24 20:00:50 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-05-27 15:52:35 +0100 |
commit | 4a10214be20cb8a51724913903678f4506358752 (patch) | |
tree | d8df91460c449cd5d8e2168225d5c9e3f9c94f17 /unix/main.c | |
parent | 2acfb7c00225c7fbc7b9fe4a4b5da450025dfc9a (diff) | |
download | micropython-4a10214be20cb8a51724913903678f4506358752.tar.gz micropython-4a10214be20cb8a51724913903678f4506358752.zip |
unix: Factor out stdio and ctrl-C code to unix_mphal.c file.
Diffstat (limited to 'unix/main.c')
-rw-r--r-- | unix/main.c | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/unix/main.c b/unix/main.c index 50b6c1e0bb..fb6868c88a 100644 --- a/unix/main.c +++ b/unix/main.c @@ -44,6 +44,7 @@ #include "py/gc.h" #include "py/stackctrl.h" #include "genhdr/mpversion.h" +#include "unix_mphal.h" #include "input.h" // Command line options, with their defaults @@ -57,22 +58,6 @@ mp_uint_t mp_verbose_flag = 0; long heap_size = 128*1024 * (sizeof(mp_uint_t) / 4); #endif -#ifndef _WIN32 -#include <signal.h> - -STATIC void sighandler(int signum) { - if (signum == SIGINT) { - 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; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - } -} -#endif - STATIC void stderr_print_strn(void *env, const char *str, mp_uint_t len) { (void)env; fwrite(str, len, 1, stderr); @@ -110,14 +95,7 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, return 1; } - #ifndef _WIN32 - // enable signal handler - struct sigaction sa; - sa.sa_handler = sighandler; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sa.sa_handler = SIG_DFL; - #endif + mp_hal_set_interrupt_char(CHAR_CTRL_C); nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { @@ -144,20 +122,13 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_call_function_0(module_fun); } - #ifndef _WIN32 - // disable signal handler - sigaction(SIGINT, &sa, NULL); - #endif - + mp_hal_set_interrupt_char(-1); nlr_pop(); return 0; } else { // uncaught exception - #ifndef _WIN32 - // disable signal handler - sigaction(SIGINT, &sa, NULL); - #endif + mp_hal_set_interrupt_char(-1); return handle_uncaught_exception((mp_obj_t)nlr.ret_val); } } @@ -177,7 +148,7 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { } STATIC int do_repl(void) { - printf("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_PY_SYS_PLATFORM " version\n"); + mp_hal_stdout_tx_str("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_PY_SYS_PLATFORM " version\n"); for (;;) { char *line = prompt(">>> "); |