summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-10-09 16:45:15 +0100
committerDamien George <damien.p.george@gmail.com>2014-10-09 16:45:15 +0100
commit7989b076376900ee6fb0ab7a86875844b5c179aa (patch)
tree5c373e6afd198e5eaf5f935542779d8067155878 /py/runtime.c
parent67f25dfe6f4b13a3b8d40746d2b2fd720c63caed (diff)
parent4091445612a14451590064f337eeb190d969d243 (diff)
downloadmicropython-7989b076376900ee6fb0ab7a86875844b5c179aa.tar.gz
micropython-7989b076376900ee6fb0ab7a86875844b5c179aa.zip
Merge branch 'dhylands-memory-error'
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 945713d18a..6efab0480c 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,17 @@ 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 (0) {
+ // dummy
+ #if MICROPY_ENABLE_GC
+ } else if (gc_is_locked()) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError,
+ "memory allocation failed, heap is locked"));
+ #endif
+ } 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) {