summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2014-10-07 00:50:20 -0700
committerDave Hylands <dhylands@gmail.com>2014-10-07 08:07:49 -0700
commit3556e45711c3b7ec712748d013e678d035185bdd (patch)
treeda58cd4deb464baafcc1771a5fd54eacc38b33d7 /py
parent67f25dfe6f4b13a3b8d40746d2b2fd720c63caed (diff)
downloadmicropython-3556e45711c3b7ec712748d013e678d035185bdd.tar.gz
micropython-3556e45711c3b7ec712748d013e678d035185bdd.zip
Allow real memory errors (from locked gc) to be reported with traceback.
Diffstat (limited to 'py')
-rw-r--r--py/runtime.c9
1 files changed, 8 insertions, 1 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) {