From 0d8cb0123b01af198fb819f67f6b7bf801450dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 20 Feb 2020 11:23:13 +0100 Subject: [PATCH] [python/port] Fix user interruption char set up print can be user interrupted, so the interruption char needs to be set for the whole runCode method --- python/port/port.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/port/port.cpp b/python/port/port.cpp index a1405ae6e..5c56064cc 100644 --- a/python/port/port.cpp +++ b/python/port/port.cpp @@ -33,6 +33,10 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) { assert(sCurrentExecutionEnvironment == nullptr); sCurrentExecutionEnvironment = this; + /* Set the user interruption now, as it is needed for the normal execution and + * for the exception handling (because of print). */ + mp_hal_set_interrupt_char((int)Ion::Keyboard::Key::Back); + nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_lexer_t *lex = mp_lexer_new_from_str_len(0, str, strlen(str), false); @@ -41,9 +45,7 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) { // TODO: add a parameter when other input types (file, eval) are required mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_SINGLE_INPUT); mp_obj_t module_fun = mp_compile(&pt, lex->source_name, MP_EMIT_OPT_NONE, true); - mp_hal_set_interrupt_char((int)Ion::Keyboard::Key::Back); mp_call_function_0(module_fun); - mp_hal_set_interrupt_char(-1); // Disable interrupt nlr_pop(); } else { // Uncaught exception /* mp_obj_print_exception is supposed to handle error printing. However, @@ -81,6 +83,9 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) { /* End of mp_obj_print_exception. */ } + // Disable the user interruption + mp_hal_set_interrupt_char(-1); + assert(sCurrentExecutionEnvironment == this); sCurrentExecutionEnvironment = nullptr; }