Commit b62c30b4 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

Generalize malloc-via-gc-heap support, make it available to unix port.

parent 8d90a382
......@@ -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; }
#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
void *m_malloc(int num_bytes) {
if (num_bytes == 0) {
return NULL;
......@@ -29,18 +29,6 @@ void *realloc(void *ptr, size_t n) {
void *malloc(size_t n) {
return gc_alloc(n);
void free(void *ptr) {
void *realloc(void *ptr, size_t n) {
return gc_realloc(ptr, n);
void __assert_func(void) {
printf("\nASSERT FAIL!");
for (;;) {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment