Skip to content

Commit

Permalink
Fix test_weakref.test_threaded_weak_key_dict_copy refleak
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Feb 8, 2024
1 parent 51c6625 commit c631856
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ _Py_DecRefSharedDebug(PyObject *o, const char *filename, int lineno)
&shared, new_shared));

if (should_queue) {
#ifdef Py_REF_DEBUG
_Py_IncRefTotal(_PyInterpreterState_GET());
#endif
_Py_brc_queue_object(o);
}
else if (new_shared == _Py_REF_MERGED) {
Expand Down Expand Up @@ -395,13 +398,13 @@ _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra)
Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
do {
refcnt = Py_ARITHMETIC_RIGHT_SHIFT(Py_ssize_t, shared, _Py_REF_SHARED_SHIFT);
if (_Py_REF_IS_MERGED(shared)) {
return refcnt;
}

refcnt += (Py_ssize_t)op->ob_ref_local;
refcnt += extra;

#ifdef Py_REF_DEBUG
_Py_AddRefTotal(_PyInterpreterState_GET(), extra);
#endif

new_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
} while (!_Py_atomic_compare_exchange_ssize(&op->ob_ref_shared,
&shared, new_shared));
Expand Down
7 changes: 6 additions & 1 deletion Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,12 @@ get_mimalloc_allocated_blocks(PyInterpreterState *interp)
mi_heap_visit_blocks(heap, false, &count_blocks, &allocated_blocks);
}
}
// TODO(sgross): count blocks in abandoned segments.

mi_abandoned_pool_t *pool = &interp->mimalloc.abandoned_pool;
for (uint8_t tag = 0; tag < _Py_MIMALLOC_HEAP_COUNT; tag++) {
_mi_abandoned_pool_visit_blocks(pool, tag, false, &count_blocks,
&allocated_blocks);
}
#else
// TODO(sgross): this only counts the current thread's blocks.
mi_heap_t *heap = mi_heap_get_default();
Expand Down

0 comments on commit c631856

Please sign in to comment.