@@ -331,7 +331,9 @@ static size_t compute_heap_size(size_t total_blocks) {
331331static bool gc_try_add_heap (size_t failed_alloc ) {
332332 // 'needed' is the size of a heap large enough to hold failed_alloc, with
333333 // the additional metadata overheads as calculated in gc_setup_area().
334+ // CIRCUITPY-CHANGE: calculation of how much to grow the heap
334335 size_t total_new_blocks = (failed_alloc + BYTES_PER_BLOCK - 1 ) / BYTES_PER_BLOCK ;
336+ // CIRCUITPY-CHANGE
335337 size_t needed = compute_heap_size (total_new_blocks );
336338
337339 size_t avail = gc_get_max_new_split ();
@@ -376,6 +378,7 @@ static bool gc_try_add_heap(size_t failed_alloc) {
376378 total_blocks += area -> gc_alloc_table_byte_len * BLOCKS_PER_ATB ;
377379 }
378380
381+ // CIRCUITPY-CHANGE
379382 size_t total_heap = compute_heap_size (total_blocks );
380383
381384 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)
498501 // check that the consecutive blocks didn't overflow past the end of the area
499502 assert (area -> gc_pool_start + (block + n_blocks ) * BYTES_PER_BLOCK <= area -> gc_pool_end );
500503
504+ // CIRCUITPY-CHANGE
501505 // check if this block should be collected
502506 #if MICROPY_ENABLE_SELECTIVE_COLLECT
503507 bool should_scan = CTB_GET (area , block );
@@ -1005,6 +1009,7 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
10051009 (void )has_finaliser ;
10061010 #endif
10071011
1012+ // CIRCUITPY-CHANGE
10081013 #if MICROPY_ENABLE_SELECTIVE_COLLECT
10091014 bool do_not_collect = (alloc_flags & GC_ALLOC_FLAG_DO_NOT_COLLECT ) != 0 ;
10101015 GC_ENTER ();
@@ -1184,6 +1189,7 @@ void *gc_realloc(void *ptr, mp_uint_t n_bytes) {
11841189void * gc_realloc (void * ptr_in , size_t n_bytes , bool allow_move ) {
11851190 // check for pure allocation
11861191 if (ptr_in == NULL ) {
1192+ // CIRCUITPY-CHANGE
11871193 return gc_alloc (n_bytes , 0 );
11881194 }
11891195
@@ -1329,6 +1335,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
13291335 }
13301336 #endif
13311337
1338+ // CIRCUITPY-CHANGE
13321339 #if MICROPY_ENABLE_SELECTIVE_COLLECT
13331340 if (!CTB_GET (area , block )) {
13341341 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) {
13431350 }
13441351
13451352 // can't resize inplace; try to find a new contiguous chain
1353+ // CIRCUITPY-CHANGE
13461354 void * ptr_out = gc_alloc (n_bytes , alloc_flags );
13471355
13481356 // check that the alloc succeeded
0 commit comments