Skip to content

Commit bca4890

Browse files
authored
[3.12] gh-127599: Fix _Py_RefcntAdd missing calls to _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (GH-127717) (#128712)
Previously, `_Py_RefcntAdd` hasn't called `_Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC` which is incorrect. Now it has been fixed. (cherry picked from commit ab05beb)
1 parent 3d9b14c commit bca4890

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Include/internal/pycore_object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
6565
_Py_AddRefTotal(_PyInterpreterState_GET(), n);
6666
#endif
6767
op->ob_refcnt += n;
68+
69+
// Although the ref count was increased by `n` (which may be greater than 1)
70+
// it is only a single increment (i.e. addition) operation, so only 1 refcnt
71+
// increment operation is counted.
72+
_Py_INCREF_STAT_INC();
6873
}
6974
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
7075

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix statistics for increments of object reference counts (in particular, when
2+
a reference count was increased by more than 1 in a single operation).

0 commit comments

Comments
 (0)