Skip to content

Commit e9d1a94

Browse files
committed
py/malloc: Provide a proper malloc-based implementation of realloc_ext.
1 parent d6c558c commit e9d1a94

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

py/malloc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@
5959
#define realloc(ptr, n) gc_realloc(ptr, n, true)
6060
#define realloc_ext(ptr, n, mv) gc_realloc(ptr, n, mv)
6161
#else
62-
#define realloc_ext(ptr, n, mv) realloc(ptr, n)
62+
STATIC void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) {
63+
if (allow_move) {
64+
return realloc(ptr, n_bytes);
65+
} else {
66+
// We are asked to resize, but without moving the memory region pointed to
67+
// by ptr. Unless the underlying memory manager has special provision for
68+
// this behaviour there is nothing we can do except fail to resize.
69+
return NULL;
70+
}
71+
}
6372
#endif // MICROPY_ENABLE_GC
6473

6574
void *m_malloc(size_t num_bytes) {

0 commit comments

Comments
 (0)