diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 22:37:09 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-11 16:20:02 +0200 |
commit | b62c30b4bc86f76ac6f48cdf374a947573af30ec (patch) | |
tree | bd298d9601acd50b4a553f4edd2a4637ea1674cb | |
parent | 8d90a382cf4124be6db3c0b187694dde26229228 (diff) | |
download | micropython-b62c30b4bc86f76ac6f48cdf374a947573af30ec.tar.gz micropython-b62c30b4bc86f76ac6f48cdf374a947573af30ec.zip |
Generalize malloc-via-gc-heap support, make it available to unix port.
-rw-r--r-- | py/malloc.c | 16 | ||||
-rw-r--r-- | stm/malloc0.c | 12 |
2 files changed, 16 insertions, 12 deletions
diff --git a/py/malloc.c b/py/malloc.c index c87d91c0a0..7f55fa7c8e 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -19,6 +19,22 @@ static int peak_bytes_allocated = 0; #define UPDATE_PEAK() { if (current_bytes_allocated > peak_bytes_allocated) peak_bytes_allocated = current_bytes_allocated; } #endif +#if MICROPY_ENABLE_GC +#include "gc.h" + +// We redirect standard alloc functions to GC heap - just for the rest of +// this module. In the rest of micropython source, system malloc can be +// freely accessed - for interfacing with system and 3rd-party libs for +// example. On the other hand, some (e.g. bare-metal) ports may use GC +// heap as system heap, so, to avoid warnings, we do undef's first. +#undef malloc +#undef free +#undef realloc +#define malloc gc_alloc +#define free gc_free +#define realloc gc_realloc +#endif // MICROPY_ENABLE_GC + void *m_malloc(int num_bytes) { if (num_bytes == 0) { return NULL; diff --git a/stm/malloc0.c b/stm/malloc0.c index eaa436f4fb..85a643f72d 100644 --- a/stm/malloc0.c +++ b/stm/malloc0.c @@ -29,18 +29,6 @@ void *realloc(void *ptr, size_t n) { #endif -void *malloc(size_t n) { - return gc_alloc(n); -} - -void free(void *ptr) { - gc_free(ptr); -} - -void *realloc(void *ptr, size_t n) { - return gc_realloc(ptr, n); -} - void __assert_func(void) { printf("\nASSERT FAIL!"); for (;;) { |