diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-27 09:54:12 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-03-03 21:23:13 +0000 |
commit | d891452a73165966497f1c79b64276faaa664597 (patch) | |
tree | 6a04e942861bbcb6a7321dffd65895f3a38056a7 /py/malloc.c | |
parent | e104acdb8ccd53963f5415edc8c9ab88aeca771a (diff) | |
download | micropython-d891452a73165966497f1c79b64276faaa664597.tar.gz micropython-d891452a73165966497f1c79b64276faaa664597.zip |
py: Add MICROPY_MALLOC_USES_ALLOCATED_SIZE to allow simpler malloc API.
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c index be2c0db02b..f8728c5964 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -109,7 +109,11 @@ void *m_malloc0(size_t num_bytes) { return ptr; } +#if MICROPY_MALLOC_USES_ALLOCATED_SIZE void *m_realloc(void *ptr, size_t old_num_bytes, size_t new_num_bytes) { +#else +void *m_realloc(void *ptr, size_t new_num_bytes) { +#endif void *new_ptr = realloc(ptr, new_num_bytes); if (new_ptr == NULL && new_num_bytes != 0) { return m_malloc_fail(new_num_bytes); @@ -129,7 +133,11 @@ void *m_realloc(void *ptr, size_t old_num_bytes, size_t new_num_bytes) { return new_ptr; } +#if MICROPY_MALLOC_USES_ALLOCATED_SIZE void *m_realloc_maybe(void *ptr, size_t old_num_bytes, size_t new_num_bytes) { +#else +void *m_realloc_maybe(void *ptr, size_t new_num_bytes) { +#endif void *new_ptr = realloc(ptr, new_num_bytes); #if MICROPY_MEM_STATS // At first thought, "Total bytes allocated" should only grow, @@ -149,7 +157,11 @@ void *m_realloc_maybe(void *ptr, size_t old_num_bytes, size_t new_num_bytes) { return new_ptr; } +#if MICROPY_MALLOC_USES_ALLOCATED_SIZE void m_free(void *ptr, size_t num_bytes) { +#else +void m_free(void *ptr) { +#endif free(ptr); #if MICROPY_MEM_STATS MP_STATE_MEM(current_bytes_allocated) -= num_bytes; |