diff options
author | Damien George <damien.p.george@gmail.com> | 2014-02-10 22:51:35 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-02-10 22:51:35 +0000 |
commit | f1081f400b3dd072fd46704d93557bd40ae617e5 (patch) | |
tree | 418dbb67431fe21ce9ca8578c3ec271a52ceded5 /py/malloc.c | |
parent | ed378cd12f05c78c735dffe1c0a6b3cb4337e67d (diff) | |
parent | 724026ab402a13a2344ac6679a665394777ff0fa (diff) | |
download | micropython-f1081f400b3dd072fd46704d93557bd40ae617e5.tar.gz micropython-f1081f400b3dd072fd46704d93557bd40ae617e5.zip |
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/py/malloc.c b/py/malloc.c index 59570243f0..c87d91c0a0 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "misc.h" #include "mpconfig.h" @@ -37,20 +38,10 @@ void *m_malloc(int num_bytes) { } void *m_malloc0(int num_bytes) { - if (num_bytes == 0) { - return NULL; - } - void *ptr = calloc(1, num_bytes); - if (ptr == NULL) { - printf("could not allocate memory, allocating %d bytes\n", num_bytes); - return NULL; + void *ptr = m_malloc(num_bytes); + if (ptr != NULL) { + memset(ptr, 0, num_bytes); } -#if MICROPY_MEM_STATS - total_bytes_allocated += num_bytes; - current_bytes_allocated += num_bytes; - UPDATE_PEAK(); -#endif - DEBUG_printf("malloc0 %d : %p\n", num_bytes, ptr); return ptr; } |