diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-05 18:49:39 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-05 18:49:39 +0100 |
commit | 8123a3339dc7381a079afa90649ce140075eb2e2 (patch) | |
tree | b41d4337c7a9e234827201be8e717b32a2ac26fe /py/malloc.c | |
parent | ea13f407a392593e7746131952a57bad222ee882 (diff) | |
parent | cc849f70f478f7442d19ed2f4c0b4297035b2393 (diff) | |
download | micropython-8123a3339dc7381a079afa90649ce140075eb2e2.tar.gz micropython-8123a3339dc7381a079afa90649ce140075eb2e2.zip |
Merge pull request #425 from iabdalkader/del
Implement del
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c index 4cf1b71db0..a07d360020 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -31,6 +31,7 @@ STATIC int peak_bytes_allocated = 0; #undef free #undef realloc #define malloc gc_alloc +#define malloc_mp_obj gc_alloc_mp_obj #define free gc_free #define realloc gc_realloc #endif // MICROPY_ENABLE_GC @@ -52,6 +53,24 @@ void *m_malloc(int num_bytes) { return ptr; } +void *m_malloc_mp_obj(int num_bytes) { + if (num_bytes == 0) { + return NULL; + } + void *ptr = malloc_mp_obj(num_bytes); + if (ptr == NULL) { + printf("could not allocate memory, allocating %d bytes\n", num_bytes); + return NULL; + } +#if MICROPY_MEM_STATS + total_bytes_allocated += num_bytes; + current_bytes_allocated += num_bytes; + UPDATE_PEAK(); +#endif + DEBUG_printf("malloc %d : %p\n", num_bytes, ptr); + return ptr; +} + void *m_malloc0(int num_bytes) { void *ptr = m_malloc(num_bytes); if (ptr != NULL) { |