Skip to content

Commit 37ada23

Browse files
committed
py: Take gc_pool_start out of bss section, to reclaim 1st block of heap.
1 parent 923a8a8 commit 37ada23

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

py/gc.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ STATIC mp_uint_t gc_alloc_table_byte_len;
5858
#if MICROPY_ENABLE_FINALISER
5959
STATIC byte *gc_finaliser_table_start;
6060
#endif
61-
STATIC mp_uint_t *gc_pool_start;
61+
// We initialise gc_pool_start to a dummy value so it stays out of the bss
62+
// section. This makes sure we don't trace this pointer in a collect cycle.
63+
// If we did trace it, it would make the first block of the heap always
64+
// reachable, and hence we can never free that block.
65+
STATIC mp_uint_t *gc_pool_start = (void*)4;
6266
STATIC mp_uint_t *gc_pool_end;
6367

6468
STATIC int gc_stack_overflow;
@@ -153,13 +157,6 @@ void gc_init(void *start, void *end) {
153157
memset(gc_finaliser_table_start, 0, gc_finaliser_table_byte_len);
154158
#endif
155159

156-
// allocate first block because gc_pool_start points there and it will never
157-
// be freed, so allocating 1 block with null pointers will minimise memory loss
158-
ATB_FREE_TO_HEAD(0);
159-
for (int i = 0; i < WORDS_PER_BLOCK; i++) {
160-
gc_pool_start[i] = 0;
161-
}
162-
163160
// set last free ATB index to start of heap
164161
gc_last_free_atb_index = 0;
165162

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy