diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-10 14:38:25 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-10 14:38:25 +0100 |
commit | f0954e3fac03c35a91e544c2ffddc12b82d7f8a0 (patch) | |
tree | 88f87cd0f2c387412953f21c9ff53adb5481e99a /py/malloc.c | |
parent | 6f355fd3b914dfb31f9d8527670448a9fc323e81 (diff) | |
download | micropython-f0954e3fac03c35a91e544c2ffddc12b82d7f8a0.tar.gz micropython-f0954e3fac03c35a91e544c2ffddc12b82d7f8a0.zip |
py: Add emergency exception object for when heap allocation fails.
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c index 45e939b6c2..1d18a9a643 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) { |