mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 19:50:30 +01:00
unix: Factor out stdio and ctrl-C code to unix_mphal.c file.
This commit is contained in:
39
unix/main.c
39
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(">>> ");
|
||||
|
||||
Reference in New Issue
Block a user