Skip to content

Commit

Permalink
Fix for adafruit#2204
Browse files Browse the repository at this point in the history
  • Loading branch information
furbrain committed May 16, 2023
1 parent 34a9c6c commit af37ae8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion py/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,15 @@ bool gc_never_free(void *ptr) {
// Pointers are stored in a linked list where each block is BYTES_PER_BLOCK long and the first
// pointer is the next block of pointers.
void **current_reference_block = MP_STATE_MEM(permanent_pointers);
void **last_reference_block = NULL;
while (current_reference_block != NULL) {
for (size_t i = 1; i < BYTES_PER_BLOCK / sizeof(void *); i++) {
if (current_reference_block[i] == NULL) {
current_reference_block[i] = ptr;
return true;
}
}
last_reference_block = current_reference_block; // keep a record of last "proper" reference block
current_reference_block = current_reference_block[0];
}
void **next_block = gc_alloc(BYTES_PER_BLOCK, false, true);
Expand All @@ -1029,7 +1031,7 @@ bool gc_never_free(void *ptr) {
if (MP_STATE_MEM(permanent_pointers) == NULL) {
MP_STATE_MEM(permanent_pointers) = next_block;
} else {
current_reference_block[0] = next_block;
last_reference_block[0] = next_block;
}
next_block[1] = ptr;
return true;
Expand Down

0 comments on commit af37ae8

Please sign in to comment.