diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 18:37:11 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 18:40:00 +0200 |
commit | 58ff93bc7c25d7d41dda28875f88652b260b9f13 (patch) | |
tree | 3cdf80894bc67ed904d7e6091f49108313c20d1d | |
parent | 2e24ee8d80de20e879275c087ecc1ca9b4d27297 (diff) | |
download | micropython-58ff93bc7c25d7d41dda28875f88652b260b9f13.tar.gz micropython-58ff93bc7c25d7d41dda28875f88652b260b9f13.zip |
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.
-rw-r--r-- | py/malloc.c | 17 | ||||
-rw-r--r-- | stm/malloc0.c | 8 | ||||
-rw-r--r-- | stm/std.h | 1 | ||||
-rw-r--r-- | teensy/std.h | 1 |
4 files changed, 4 insertions, 23 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; } diff --git a/stm/malloc0.c b/stm/malloc0.c index 7e3f620db2..eaa436f4fb 100644 --- a/stm/malloc0.c +++ b/stm/malloc0.c @@ -29,14 +29,6 @@ void *realloc(void *ptr, size_t n) { #endif -void *calloc(size_t sz, size_t n) { - char *ptr = malloc(sz * n); - for (int i = 0; i < sz * n; i++) { - ptr[i] = 0; - } - return ptr; -} - void *malloc(size_t n) { return gc_alloc(n); } @@ -4,7 +4,6 @@ void __assert_func(void); void *malloc(size_t n); void free(void *ptr); -void *calloc(size_t sz, size_t n); void *realloc(void *ptr, size_t n); void *memcpy(void *dest, const void *src, size_t n); diff --git a/teensy/std.h b/teensy/std.h index 587b9f8880..6b768e7c8d 100644 --- a/teensy/std.h +++ b/teensy/std.h @@ -4,7 +4,6 @@ void __assert_func(void); void *malloc(size_t n); void free(void *ptr); -void *calloc(size_t sz, size_t n); void *realloc(void *ptr, size_t n); void *memcpy(void *dest, const void *src, size_t n); |