Skip to content

Commit 652cf33

Browse files
committed
Add assert for buffer size settings.
1 parent abfc49a commit 652cf33

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Python/gc_free_threading.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,20 @@ gc_maybe_untrack(PyObject *op)
485485
// enough time between the enqueue and dequeue so that the needed memory
486486
// for the object, most importantly ob_gc_bits and ob_type words, will
487487
// already be in the CPU cache.
488-
#define BUFFER_SIZE 256 // this must be a power of 2
488+
#define BUFFER_SIZE 256
489489
#define BUFFER_HI 16
490490
#define BUFFER_LO 8
491491
#define BUFFER_MASK (BUFFER_SIZE - 1)
492492

493+
// the buffer size must be an exact power of two
494+
static_assert(BUFFER_SIZE > 0 && !(BUFFER_SIZE & BUFFER_MASK),
495+
"Invalid BUFFER_SIZE, must be power of 2");
496+
// the code below assumes these relationships are true
497+
static_assert(BUFFER_HI < BUFFER_SIZE &&
498+
BUFFER_LO < BUFFER_HI &&
499+
BUFFER_LO > 0,
500+
"Invalid prefetch buffer level settings.");
501+
493502
// Prefetch intructions will fetch the line of data from memory that
494503
// contains the byte specified with the source operand to a location in
495504
// the cache hierarchy specified by a locality hint. The instruction
@@ -1183,7 +1192,7 @@ gc_prime_from_spans(gc_mark_args_t *args)
11831192
gc_mark_buffer_push(op, args);
11841193
space--;
11851194
if (space == 0) {
1186-
// buffer is as full was we want and not done with span
1195+
// buffer is as full as we want and not done with span
11871196
gc_mark_span_push(&args->spans, entry.start, entry.end);
11881197
return;
11891198
}

0 commit comments

Comments
 (0)