Skip to content

Commit 5a162eb

Browse files
committed
gc.c: Ensure a gap of one byte before the finaliser table.
.. or, for !MICROPY_ENABLE_FINALISER, before the first block of the pool. Closes: adafruit#5021 Closes: micropython#7116 Signed-off-by: Jeff Epler <[email protected]>
1 parent 15133cb commit 5a162eb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

py/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void gc_init(void *start, void *end) {
122122
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK)
123123
size_t total_byte_len = (byte *)end - (byte *)start;
124124
#if MICROPY_ENABLE_FINALISER
125-
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len * MP_BITS_PER_BYTE / (MP_BITS_PER_BYTE + MP_BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + MP_BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);
125+
MP_STATE_MEM(gc_alloc_table_byte_len) = (total_byte_len - 1) * MP_BITS_PER_BYTE / (MP_BITS_PER_BYTE + MP_BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + MP_BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);
126126
#else
127127
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len / (1 + MP_BITS_PER_BYTE / 2 * BYTES_PER_BLOCK);
128128
#endif
@@ -131,7 +131,7 @@ void gc_init(void *start, void *end) {
131131

132132
#if MICROPY_ENABLE_FINALISER
133133
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;
134-
MP_STATE_MEM(gc_finaliser_table_start) = MP_STATE_MEM(gc_alloc_table_start) + MP_STATE_MEM(gc_alloc_table_byte_len);
134+
MP_STATE_MEM(gc_finaliser_table_start) = MP_STATE_MEM(gc_alloc_table_start) + MP_STATE_MEM(gc_alloc_table_byte_len) + 1;
135135
#endif
136136

137137
size_t gc_pool_block_len = MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB;

0 commit comments

Comments
 (0)