Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix allocation count decrement and GC state update
Adjust allocation count handling to prevent negative values and update GC state accordingly.
  • Loading branch information
kevmo314 authored Dec 1, 2025
commit 9388518613c625629ca3f289561743f7fd952de1
21 changes: 17 additions & 4 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -2207,10 +2207,23 @@ record_deallocation(PyThreadState *tstate)
{
struct _gc_thread_state *gc = &((_PyThreadStateImpl *)tstate)->gc;

// Only decrement if positive, matching gc.c behavior which prevents
// negative counts (see PyObject_GC_Del in gc.c).
if (gc->alloc_count > 0) {
gc->alloc_count--;
gc->alloc_count--;
if (gc->alloc_count <= -LOCAL_ALLOC_COUNT_THRESHOLD) {
GCState *gcstate = &tstate->interp->gc;
int count = _Py_atomic_load_int_relaxed(&gcstate->young.count);
int new_count;
do {
if (count == 0){
break;
}
new_count = count + (int)gc->alloc_count;
if (new_count < 0) {
new_count = 0;
}
} while (!_Py_atomic_compare_exchange_int(&gcstate->young.count,
&count,
new_count));
gc->alloc_count = 0;
}
}

Expand Down
Loading