Skip to content

Commit 86a5c95

Browse files
committed
Add some asserts, minor code cleanup.
1 parent 041b2e4 commit 86a5c95

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Python/gc_free_threading.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ gc_maybe_untrack(PyObject *op)
502502
#define prefetch(ptr)
503503
#endif
504504

505-
// a contigous sequence of PyObject pointers
505+
// a contigous sequence of PyObject pointers, can contain NULLs
506506
typedef struct {
507507
PyObject **start;
508508
PyObject **end;
@@ -548,6 +548,7 @@ gc_mark_span_push(gc_span_stack_t *ss, PyObject **start, PyObject **end)
548548
return -1;
549549
}
550550
}
551+
assert(end > start);
551552
ss->stack[ss->size].start = start;
552553
ss->stack[ss->size].end = end;
553554
ss->size++;
@@ -560,12 +561,12 @@ static void
560561
gc_mark_buffer_push(PyObject *op, gc_mark_args_t *args)
561562
{
562563
#ifdef Py_DEBUG
563-
Py_ssize_t buf_used = args->enqueued - args->dequeued;
564-
assert(buf_used < BUFFER_SIZE);
564+
Py_ssize_t buf_used = args->enqueued - args->dequeued;
565+
assert(buf_used < BUFFER_SIZE);
565566
#endif
566-
prefetch(op);
567-
args->buffer[args->enqueued % BUFFER_SIZE] = op;
568-
args->enqueued++;
567+
prefetch(op);
568+
args->buffer[args->enqueued % BUFFER_SIZE] = op;
569+
args->enqueued++;
569570
}
570571

571572
// Called when we find an object that needs to be marked alive (either from a
@@ -598,6 +599,7 @@ gc_mark_enqueue_span(PyObject **item, Py_ssize_t size, gc_mark_args_t *args)
598599
}
599600
}
600601
else {
602+
assert(size > 0);
601603
PyObject **end = &item[size];
602604
if (gc_mark_span_push(&args->spans, item, end) < 0) {
603605
return -1;

0 commit comments

Comments
 (0)