@@ -138,7 +138,6 @@ void gc_init(void *start, void *end) {
138
138
MP_STATE_MEM (gc_alloc_table_start ) = (byte * )start ;
139
139
140
140
#if MICROPY_ENABLE_FINALISER
141
- size_t gc_finaliser_table_byte_len = (MP_STATE_MEM (gc_alloc_table_byte_len ) * BLOCKS_PER_ATB + BLOCKS_PER_FTB - 1 ) / BLOCKS_PER_FTB ;
142
141
MP_STATE_MEM (gc_finaliser_table_start ) = MP_STATE_MEM (gc_alloc_table_start ) + MP_STATE_MEM (gc_alloc_table_byte_len ) + 1 ;
143
142
#endif
144
143
@@ -150,15 +149,11 @@ void gc_init(void *start, void *end) {
150
149
assert (MP_STATE_MEM (gc_pool_start ) >= MP_STATE_MEM (gc_finaliser_table_start ) + gc_finaliser_table_byte_len );
151
150
#endif
152
151
153
- // Clear ATBs plus one more byte. The extra byte might be read when we read the final ATB and
154
- // then try to count its tail. Clearing the byte ensures it is 0 and ends the chain. Without an
155
- // FTB, it'll just clear the pool byte early.
156
- memset (MP_STATE_MEM (gc_alloc_table_start ), 0 , MP_STATE_MEM (gc_alloc_table_byte_len ) + 1 );
157
-
158
- #if MICROPY_ENABLE_FINALISER
159
- // clear FTBs
160
- memset (MP_STATE_MEM (gc_finaliser_table_start ), 0 , gc_finaliser_table_byte_len );
161
- #endif
152
+ // Clear ATBs & finalisers (if enabled). This also clears the extra byte
153
+ // which appears between ATBs and finalisers that ensures every chain in
154
+ // the ATB terminates, rather than erroneously using bits from the
155
+ // finalisers.
156
+ memset (MP_STATE_MEM (gc_alloc_table_start ), 0 , MP_STATE_MEM (gc_pool_start ) - MP_STATE_MEM (gc_alloc_table_start ));
162
157
163
158
// Set first free ATB index to the start of the heap.
164
159
for (size_t i = 0 ; i < MICROPY_ATB_INDICES ; i ++ ) {
0 commit comments