summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-04 10:52:59 +0000
committerDamien George <damien.p.george@gmail.com>2014-04-04 10:52:59 +0000
commit6902eeda259a5ed8fe3a5ce5cb19ba9207549d33 (patch)
treed018a0c7a42e03d0705efedbd116ac5de3ad886d /py/runtime.c
parent072cf022e007e03a8b850a7197585403868923ab (diff)
downloadmicropython-6902eeda259a5ed8fe3a5ce5cb19ba9207549d33.tar.gz
micropython-6902eeda259a5ed8fe3a5ce5cb19ba9207549d33.zip
py: Add m_malloc_fail function to handle memory allocation error.
A malloc/realloc fail now throws MemoryError.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/runtime.c b/py/runtime.c
index d9e2298c4c..a5afe0e750 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -1034,6 +1034,11 @@ void mp_globals_set(mp_map_t *m) {
map_globals = m;
}
+void *m_malloc_fail(int num_bytes) {
+ DEBUG_printf("memory allocation failed, allocating %d bytes\n", num_bytes);
+ nlr_jump((mp_obj_t)&mp_const_MemoryError_obj);
+}
+
// these must correspond to the respective enum
void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_load_const_dec,