aboutsummaryrefslogtreecommitdiff
path: root/py/malloc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-10 14:38:25 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-10 14:38:25 +0100
commitf0954e3fac03c35a91e544c2ffddc12b82d7f8a0 (patch)
tree88f87cd0f2c387412953f21c9ff53adb5481e99a /py/malloc.c
parent6f355fd3b914dfb31f9d8527670448a9fc323e81 (diff)
py: Add emergency exception object for when heap allocation fails.
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c
index 45e939b6c..1d18a9a64 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -53,6 +53,20 @@ void *m_malloc(int num_bytes) {
return ptr;
}
+void *m_malloc_maybe(int num_bytes) {
+ void *ptr = malloc(num_bytes);
+ if (ptr == NULL) {
+ return NULL;
+ }
+#if MICROPY_MEM_STATS
+ total_bytes_allocated += num_bytes;
+ current_bytes_allocated += num_bytes;
+ UPDATE_PEAK();
+#endif
+ DEBUG_printf("malloc %d : %p\n", num_bytes, ptr);
+ return ptr;
+}
+
#if MICROPY_ENABLE_FINALISER
void *m_malloc_with_finaliser(int num_bytes) {
if (num_bytes == 0) {