Skip to content

Commit 9ef4be8

Browse files
committed
py/gc: Add CLEAR_ON_SWEEP option to debug mis-traced objects.
Accessing them will crash immediately instead still working for some time, until overwritten by some other data, leading to much less deterministic crashes.
1 parent 9ebc037 commit 9ef4be8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

py/gc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
// make this 1 to dump the heap each time it changes
4545
#define EXTENSIVE_HEAP_PROFILING (0)
4646

47+
// make this 1 to zero out swept memory to more eagerly
48+
// detect untraced object still in use
49+
#define CLEAR_ON_SWEEP (0)
50+
4751
#define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD)
4852
#define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK)
4953

@@ -286,6 +290,9 @@ STATIC void gc_sweep(void) {
286290
case AT_TAIL:
287291
if (free_tail) {
288292
ATB_ANY_TO_FREE(block);
293+
#if CLEAR_ON_SWEEP
294+
memset((void*)PTR_FROM_BLOCK(block), 0, BYTES_PER_BLOCK);
295+
#endif
289296
}
290297
break;
291298

0 commit comments

Comments
 (0)