File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed
Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,22 @@ static int peak_bytes_allocated = 0;
1919#define UPDATE_PEAK () { if (current_bytes_allocated > peak_bytes_allocated) peak_bytes_allocated = current_bytes_allocated; }
2020#endif
2121
22+ #if MICROPY_ENABLE_GC
23+ #include "gc.h"
24+
25+ // We redirect standard alloc functions to GC heap - just for the rest of
26+ // this module. In the rest of micropython source, system malloc can be
27+ // freely accessed - for interfacing with system and 3rd-party libs for
28+ // example. On the other hand, some (e.g. bare-metal) ports may use GC
29+ // heap as system heap, so, to avoid warnings, we do undef's first.
30+ #undef malloc
31+ #undef free
32+ #undef realloc
33+ #define malloc gc_alloc
34+ #define free gc_free
35+ #define realloc gc_realloc
36+ #endif // MICROPY_ENABLE_GC
37+
2238void * m_malloc (int num_bytes ) {
2339 if (num_bytes == 0 ) {
2440 return NULL ;
Original file line number Diff line number Diff line change @@ -29,18 +29,6 @@ void *realloc(void *ptr, size_t n) {
2929
3030#endif
3131
32- void * malloc (size_t n ) {
33- return gc_alloc (n );
34- }
35-
36- void free (void * ptr ) {
37- gc_free (ptr );
38- }
39-
40- void * realloc (void * ptr , size_t n ) {
41- return gc_realloc (ptr , n );
42- }
43-
4432void __assert_func (void ) {
4533 printf ("\nASSERT FAIL!" );
4634 for (;;) {
You can’t perform that action at this time.
0 commit comments