From 3556e45711c3b7ec712748d013e678d035185bdd Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Tue, 7 Oct 2014 00:50:20 -0700 Subject: [PATCH] Allow real memory errors (from locked gc) to be reported with traceback. --- py/runtime.c | 9 ++++++++- stmhal/printf.c | 3 ++- unix/mpconfigport.h | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/py/runtime.c b/py/runtime.c index 945713d18a..71979c09b6 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -51,6 +51,7 @@ #include "parsehelper.h" #include "compile.h" #include "stackctrl.h" +#include "gc.h" #if 0 // print debugging info #define DEBUG_PRINT (1) @@ -1207,7 +1208,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i void *m_malloc_fail(size_t num_bytes) { DEBUG_printf("memory allocation failed, allocating " UINT_FMT " bytes\n", num_bytes); - nlr_raise((mp_obj_t)&mp_const_MemoryError_obj); + if (gc_is_locked()) { + nlr_raise(mp_obj_new_exception_msg(& mp_type_MemoryError, + "memory allocation failed, heap is locked")); + } else { + nlr_raise(mp_obj_new_exception_msg_varg(& mp_type_MemoryError, + "memory allocation failed, allocating " UINT_FMT " bytes", num_bytes)); + } } NORETURN void mp_not_implemented(const char *msg) { diff --git a/stmhal/printf.c b/stmhal/printf.c index 86b756f7d4..137189b94d 100644 --- a/stmhal/printf.c +++ b/stmhal/printf.c @@ -67,8 +67,9 @@ int vprintf(const char *fmt, va_list ap) { } #if MICROPY_DEBUG_PRINTERS +mp_uint_t mp_verbose_flag = 1; + int DEBUG_printf(const char *fmt, ...) { - (void)stream; va_list ap; va_start(ap, fmt); int ret = pfenv_vprintf(&pfenv_stdout, fmt, ap); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index b13fa16a72..4475c93f70 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -72,7 +72,7 @@ #endif #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) -#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (128) +#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256) extern const struct _mp_obj_module_t mp_module_os; extern const struct _mp_obj_module_t mp_module_time;