@@ -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
@@ -147,18 +146,16 @@ void gc_init(void *start, void *end) {
147
146
MP_STATE_MEM (gc_pool_end ) = end ;
148
147
149
148
#if MICROPY_ENABLE_FINALISER
149
+ 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 ;
150
+ (void )gc_finaliser_table_byte_len ; // avoid unused variable diagnostic if asserts are disabled
150
151
assert (MP_STATE_MEM (gc_pool_start ) >= MP_STATE_MEM (gc_finaliser_table_start ) + gc_finaliser_table_byte_len );
151
152
#endif
152
153
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
154
+ // Clear ATBs & finalisers (if enabled). This also clears the extra byte
155
+ // which appears between ATBs and finalisers that ensures every chain in
156
+ // the ATB terminates, rather than erroneously using bits from the
157
+ // finalisers.
158
+ memset (MP_STATE_MEM (gc_alloc_table_start ), 0 , MP_STATE_MEM (gc_pool_start ) - MP_STATE_MEM (gc_alloc_table_start ));
162
159
163
160
// Set first free ATB index to the start of the heap.
164
161
for (size_t i = 0 ; i < MICROPY_ATB_INDICES ; i ++ ) {
0 commit comments