@@ -331,7 +331,9 @@ static size_t compute_heap_size(size_t total_blocks) {
331
331
static bool gc_try_add_heap (size_t failed_alloc ) {
332
332
// 'needed' is the size of a heap large enough to hold failed_alloc, with
333
333
// the additional metadata overheads as calculated in gc_setup_area().
334
+ // CIRCUITPY-CHANGE: calculation of how much to grow the heap
334
335
size_t total_new_blocks = (failed_alloc + BYTES_PER_BLOCK - 1 ) / BYTES_PER_BLOCK ;
336
+ // CIRCUITPY-CHANGE
335
337
size_t needed = compute_heap_size (total_new_blocks );
336
338
337
339
size_t avail = gc_get_max_new_split ();
@@ -376,6 +378,7 @@ static bool gc_try_add_heap(size_t failed_alloc) {
376
378
total_blocks += area -> gc_alloc_table_byte_len * BLOCKS_PER_ATB ;
377
379
}
378
380
381
+ // CIRCUITPY-CHANGE
379
382
size_t total_heap = compute_heap_size (total_blocks );
380
383
381
384
DEBUG_printf ("total_heap " UINT_FMT " bytes\n" , total_heap );
@@ -498,6 +501,7 @@ static void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(size_t block)
498
501
// check that the consecutive blocks didn't overflow past the end of the area
499
502
assert (area -> gc_pool_start + (block + n_blocks ) * BYTES_PER_BLOCK <= area -> gc_pool_end );
500
503
504
+ // CIRCUITPY-CHANGE
501
505
// check if this block should be collected
502
506
#if MICROPY_ENABLE_SELECTIVE_COLLECT
503
507
bool should_scan = CTB_GET (area , block );
@@ -1005,6 +1009,7 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
1005
1009
(void )has_finaliser ;
1006
1010
#endif
1007
1011
1012
+ // CIRCUITPY-CHANGE
1008
1013
#if MICROPY_ENABLE_SELECTIVE_COLLECT
1009
1014
bool do_not_collect = (alloc_flags & GC_ALLOC_FLAG_DO_NOT_COLLECT ) != 0 ;
1010
1015
GC_ENTER ();
@@ -1184,6 +1189,7 @@ void *gc_realloc(void *ptr, mp_uint_t n_bytes) {
1184
1189
void * gc_realloc (void * ptr_in , size_t n_bytes , bool allow_move ) {
1185
1190
// check for pure allocation
1186
1191
if (ptr_in == NULL ) {
1192
+ // CIRCUITPY-CHANGE
1187
1193
return gc_alloc (n_bytes , 0 );
1188
1194
}
1189
1195
@@ -1329,6 +1335,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
1329
1335
}
1330
1336
#endif
1331
1337
1338
+ // CIRCUITPY-CHANGE
1332
1339
#if MICROPY_ENABLE_SELECTIVE_COLLECT
1333
1340
if (!CTB_GET (area , block )) {
1334
1341
alloc_flags |= GC_ALLOC_FLAG_DO_NOT_COLLECT ;
@@ -1343,6 +1350,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
1343
1350
}
1344
1351
1345
1352
// can't resize inplace; try to find a new contiguous chain
1353
+ // CIRCUITPY-CHANGE
1346
1354
void * ptr_out = gc_alloc (n_bytes , alloc_flags );
1347
1355
1348
1356
// check that the alloc succeeded
0 commit comments