]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-127599: Fix _Py_RefcntAdd missing calls to _Py_INCREF_STAT_INC/_Py_INCREF_I...
authorEd Nutting <github@ednutting.com>
Sat, 18 Jan 2025 17:00:18 +0000 (17:00 +0000)
committerGitHub <noreply@github.com>
Sat, 18 Jan 2025 17:00:18 +0000 (19:00 +0200)
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 ab05beb8cea62636bd86f6f7cf1a82d7efca7162)

Include/internal/pycore_object.h
Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst [new file with mode: 0644]

index 546f98d96d36ec5133c99235bafb0d1d8b2cdde1..de82d9e76f3ca141666159400b57a37232e1de25 100644 (file)
@@ -65,6 +65,11 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
     _Py_AddRefTotal(_PyInterpreterState_GET(), n);
 #endif
     op->ob_refcnt += n;
+
+    // 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)
 
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
new file mode 100644 (file)
index 0000000..565ecb8
--- /dev/null
@@ -0,0 +1,2 @@
+Fix statistics for increments of object reference counts (in particular, when
+a reference count was increased by more than 1 in a single operation).