Skip to content

Commit 9321828

Browse files
committed
py: Add ability to manually mark blocks during collect.
1 parent f03a9ac commit 9321828

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

py/gc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ void gc_info(gc_info_t *info) {
392392
GC_EXIT();
393393
}
394394

395+
void gc_mark_block(void * ptr) {
396+
if (VERIFY_PTR(ptr)) {
397+
size_t _block = BLOCK_FROM_PTR(ptr);
398+
if (ATB_GET_KIND(_block) == AT_HEAD) {
399+
/* an unmarked head, mark it, and push it on gc stack */
400+
ATB_HEAD_TO_MARK(_block);
401+
}
402+
}
403+
}
404+
395405
void *gc_alloc(size_t n_bytes, bool has_finaliser) {
396406
size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
397407
DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks);

py/gc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void gc_collect_start(void);
4545
void gc_collect_root(void **ptrs, size_t len);
4646
void gc_collect_end(void);
4747

48+
// During a collect, use this to mark blocks used in C but allocated using gc_alloc.
49+
void gc_mark_block(void * ptr);
50+
4851
void *gc_alloc(size_t n_bytes, bool has_finaliser);
4952
void gc_free(void *ptr); // does not call finaliser
5053
size_t gc_nbytes(const void *ptr);

0 commit comments

Comments
 (0)