From 58ff93bc7c25d7d41dda28875f88652b260b9f13 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 10 Feb 2014 18:37:11 +0200 Subject: Get rid of calloc(). If there's malloc and memset, then there's no need for calloc, especially if we need to implement it ourselves. --- py/malloc.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'py/malloc.c') diff --git a/py/malloc.c b/py/malloc.c index 59570243f..c87d91c0a 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -1,5 +1,6 @@ #include #include +#include #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; } -- cgit v1.2.3