diff options
author | Damien George <damien.p.george@gmail.com> | 2016-02-23 13:53:38 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-02-23 13:53:38 +0000 |
commit | e9d1a94bf099d585d0f8d3b0dddb8e0a397afcff (patch) | |
tree | f23387ae3e97741d6cb080ffc56dd8b45905a55b /py/malloc.c | |
parent | d6c558c0aae53d3cd5f8871394f44bd23836307e (diff) | |
download | micropython-e9d1a94bf099d585d0f8d3b0dddb8e0a397afcff.tar.gz micropython-e9d1a94bf099d585d0f8d3b0dddb8e0a397afcff.zip |
py/malloc: Provide a proper malloc-based implementation of realloc_ext.
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/py/malloc.c b/py/malloc.c index 0aecbd71d4..b0493d9341 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -59,7 +59,16 @@ #define realloc(ptr, n) gc_realloc(ptr, n, true) #define realloc_ext(ptr, n, mv) gc_realloc(ptr, n, mv) #else -#define realloc_ext(ptr, n, mv) realloc(ptr, n) +STATIC void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) { + if (allow_move) { + return realloc(ptr, n_bytes); + } else { + // We are asked to resize, but without moving the memory region pointed to + // by ptr. Unless the underlying memory manager has special provision for + // this behaviour there is nothing we can do except fail to resize. + return NULL; + } +} #endif // MICROPY_ENABLE_GC void *m_malloc(size_t num_bytes) { |