diff options
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) { |