//
// Define _PY_INTERPRETER macro to increment interpreter_increfs and
// interpreter_decrefs. Otherwise, increment increfs and decrefs.
+//
+// The number of incref operations counted by `incref` and
+// `interpreter_incref` is the number of increment operations, which is
+// not equal to the total of all reference counts. A single increment
+// operation may increase the reference count of an object by more than
+// one. For example, see `_Py_RefcntAdd`.
#ifndef Py_CPYTHON_PYSTATS_H
# error "this header file must not be included directly"
static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
{
if (_Py_IsImmortal(op)) {
+ _Py_INCREF_IMMORTAL_STAT_INC();
return;
}
#ifdef Py_REF_DEBUG
_Py_atomic_add_ssize(&op->ob_ref_shared, (n << _Py_REF_SHARED_SHIFT));
}
#endif
+ // Although the ref count was increased by `n` (which may be greater than 1)
+ // it is only a single increment (i.e. addition) operation, so only 1 refcnt
+ // increment operation is counted.
+ _Py_INCREF_STAT_INC();
}
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
--- /dev/null
+Fix statistics for increments of object reference counts (in particular, when
+a reference count was increased by more than 1 in a single operation).