From 46c3ab20049af16e97863e90e5761fae329f872a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 6 Dec 2014 14:29:09 +0200 Subject: modsys: Add sys.print_exception(exc, file=sys.stdout) function. The function is modeled after traceback.print_exception(), but unbloated, and put into existing module to save overhead on adding another module. Compliant traceback.print_exception() is intended to be implemented in micropython-lib in terms of sys.print_exception(). This change required refactoring mp_obj_print_exception() to take pfenv_t interface arguments. Addresses #751. --- stmhal/extint.c | 3 ++- stmhal/pyexec.c | 5 +++-- stmhal/timer.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'stmhal') diff --git a/stmhal/extint.c b/stmhal/extint.c index 4fab7c5f2..a67af65b0 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -37,6 +37,7 @@ #include "gc.h" #include "obj.h" #include "runtime.h" +#include "pfenv.h" #include "pin.h" #include "extint.h" @@ -373,7 +374,7 @@ void Handle_EXTI_Irq(uint32_t line) { v->callback_obj = mp_const_none; extint_disable(line); printf("Uncaught exception in ExtInt interrupt handler line %lu\n", line); - mp_obj_print_exception((mp_obj_t)nlr.ret_val); + mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val); } gc_unlock(); } diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c index 36a496aa1..d62b2a373 100644 --- a/stmhal/pyexec.c +++ b/stmhal/pyexec.c @@ -48,6 +48,7 @@ #include "pyexec.h" #include "pybstdio.h" #include "genhdr/py-version.h" +#include "pfenv.h" pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; STATIC bool repl_display_debugging_info = 0; @@ -87,7 +88,7 @@ STATIC int parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_ki if (exec_flags & EXEC_FLAG_PRINT_EOF) { stdout_tx_strn("\x04", 1); } - mp_obj_print_exception(module_fun); + mp_obj_print_exception(printf_wrapper, NULL, module_fun); goto finish; } @@ -116,7 +117,7 @@ STATIC int parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_ki // at the moment, the value of SystemExit is unused ret = PYEXEC_FORCED_EXIT; } else { - mp_obj_print_exception((mp_obj_t)nlr.ret_val); + mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val); ret = 0; } } diff --git a/stmhal/timer.c b/stmhal/timer.c index 5c99d51f1..e95fb5f9e 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -42,6 +42,7 @@ #include "timer.h" #include "servo.h" #include "pin.h" +#include "pfenv.h" /// \moduleref pyb /// \class Timer - periodically call a function @@ -1245,7 +1246,7 @@ STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_o } else { printf("uncaught exception in Timer(%u) channel %u interrupt handler\n", tim->tim_id, channel); } - mp_obj_print_exception((mp_obj_t)nlr.ret_val); + mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val); } gc_unlock(); } -- cgit v1.2.3