Skip to content

Commit 5453d88

Browse files
committed
py/gc: Factor out a macro to trace GC mark operations.
To allow easier override it for custom tracing.
1 parent 39dd89f commit 5453d88

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

py/gc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,22 @@ bool gc_is_locked(void) {
195195
&& ptr < (void*)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \
196196
)
197197

198+
#ifndef TRACE_MARK
199+
#if DEBUG_PRINT
200+
#define TRACE_MARK(block, ptr) DEBUG_printf("gc_mark(%p)\n", ptr)
201+
#else
202+
#define TRACE_MARK(block, ptr)
203+
#endif
204+
#endif
205+
198206
// ptr should be of type void*
199207
#define VERIFY_MARK_AND_PUSH(ptr) \
200208
do { \
201209
if (VERIFY_PTR(ptr)) { \
202210
size_t _block = BLOCK_FROM_PTR(ptr); \
203211
if (ATB_GET_KIND(_block) == AT_HEAD) { \
204212
/* an unmarked head, mark it, and push it on gc stack */ \
205-
DEBUG_printf("gc_mark(%p)\n", ptr); \
213+
TRACE_MARK(_block, ptr); \
206214
ATB_HEAD_TO_MARK(_block); \
207215
if (MP_STATE_MEM(gc_sp) < &MP_STATE_MEM(gc_stack)[MICROPY_ALLOC_GC_STACK_SIZE]) { \
208216
*MP_STATE_MEM(gc_sp)++ = _block; \

0 commit comments

Comments
 (0)