summaryrefslogtreecommitdiffstatshomepage
path: root/py/malloc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-02-11 21:42:09 +0000
committerDamien George <damien.p.george@gmail.com>2014-02-11 21:42:09 +0000
commit323f39a2b383ba1f4b65f5cd786a2531589d1677 (patch)
treeb1c589947293ee36e00a1fe6813b5feb710126a9 /py/malloc.c
parent0d14d1301667132ea12ae37ff8fe8b04842a69f1 (diff)
parent723a6ed37175fcade87802c8ab44325971446020 (diff)
downloadmicropython-323f39a2b383ba1f4b65f5cd786a2531589d1677.tar.gz
micropython-323f39a2b383ba1f4b65f5cd786a2531589d1677.zip
Merge pull request #278 from pfalcon/unix-gc
Enable GC for Unix port
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c16
1 files changed, 16 insertions, 0 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;