Skip to content

Commit ed162b5

Browse files
committed
gc: Recover simple gc_realloc implementation, make easier to switch between.
1 parent 9fd02e1 commit ed162b5

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

py/gc.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,14 @@ void *gc_realloc(void *ptr, machine_uint_t n_bytes) {
434434
if (n_bytes <= n_existing) {
435435
return ptr;
436436
} else {
437-
// TODO check if we can grow inplace
438-
void *ptr2 = gc_alloc(n_bytes);
437+
// TODO false is incorrect! Should get value from current block!
438+
void *ptr2 = gc_alloc(n_bytes,
439+
#if MICROPY_ENABLE_FINALISER
440+
FTB_GET(BLOCK_FROM_PTR((machine_uint_t)ptr))
441+
#else
442+
false
443+
#endif
444+
);
439445
if (ptr2 == NULL) {
440446
return ptr2;
441447
}
@@ -444,7 +450,8 @@ void *gc_realloc(void *ptr, machine_uint_t n_bytes) {
444450
return ptr2;
445451
}
446452
}
447-
#endif
453+
454+
#else // Alternative gc_realloc impl
448455

449456
void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) {
450457
if (gc_lock_depth > 0) {
@@ -524,6 +531,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) {
524531

525532
return ptr_out;
526533
}
534+
#endif // Alternative gc_realloc impl
527535

528536
void gc_dump_info() {
529537
gc_info_t info;

0 commit comments

Comments
 (0)