From 6eb4ec8c3bf1afd3e13c8b291e4b8d9a30731178 Mon Sep 17 00:00:00 2001 From: Mazin Sharaf Date: Tue, 7 Apr 2026 10:59:22 +1000 Subject: [PATCH 1/5] Fix calculation of PyListObject size in allocator --- Objects/listobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 5c9fd55bab1b22..2e53a440584786 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -234,7 +234,7 @@ _PyList_DebugMallocStats(FILE *out) _PyDebugAllocatorStats(out, "free PyListObject", _Py_FREELIST_SIZE(lists), - sizeof(PyListObject)); + _PyType_PreHeaderSize(&PyList_Type) + sizeof(PyListObject)); } PyObject * From 8dfae59679c915e717025768ebd8ec80379ffeb7 Mon Sep 17 00:00:00 2001 From: Mazin Sharaf Date: Tue, 7 Apr 2026 11:06:12 +1000 Subject: [PATCH 2/5] Fix size calculation in _PyDict_DebugMallocStats --- Objects/dictobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 67bc4319e0bae2..fc8f3a6209698b 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -443,7 +443,7 @@ _PyDict_DebugMallocStats(FILE *out) { _PyDebugAllocatorStats(out, "free PyDictObject", _Py_FREELIST_SIZE(dicts), - sizeof(PyDictObject)); + _PyType_PreHeaderSize(&PyDict_Type) + sizeof(PyDictObject)); _PyDebugAllocatorStats(out, "free PyDictKeysObject", _Py_FREELIST_SIZE(dictkeys), sizeof(PyDictKeysObject)); From 71e8db73c8f90385029acb3e91722e5df9b7d23c Mon Sep 17 00:00:00 2001 From: Mazin Sharaf Date: Tue, 7 Apr 2026 20:33:31 +1000 Subject: [PATCH 3/5] Fix memory size calculation in tupleobject.c Adjusted memory calculation for PyTupleObject freelist entries. --- Objects/tupleobject.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index ee6320e6ca3cfe..43e1e0446df7d2 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1274,6 +1274,7 @@ _PyTuple_DebugMallocStats(FILE *out) PyOS_snprintf(buf, sizeof(buf), "free %d-sized PyTupleObject", len); _PyDebugAllocatorStats(out, buf, _Py_FREELIST_SIZE(tuples[i]), - _PyObject_VAR_SIZE(&PyTuple_Type, len)); + /* If you would like, you could remove the _PyType_PreHeaderSize(&PyTuple_Type) + to make it so that the freelist entries actual memory is calculated */ + _PyType_PreHeaderSize(&PyTuple_Type) + _PyObject_VAR_SIZE(&PyTuple_Type, len)); } } From 47e841a6bbfebfec7cc952d79fe86bd3c3f10b29 Mon Sep 17 00:00:00 2001 From: Mazin Sharaf Date: Wed, 8 Apr 2026 12:44:52 +1000 Subject: [PATCH 4/5] Revert in tupleobject.c Removed unnecessary comment regarding memory calculation and the memory calculation itself. --- Objects/tupleobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 43e1e0446df7d2..ee6320e6ca3cfe 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1274,7 +1274,6 @@ _PyTuple_DebugMallocStats(FILE *out) PyOS_snprintf(buf, sizeof(buf), "free %d-sized PyTupleObject", len); _PyDebugAllocatorStats(out, buf, _Py_FREELIST_SIZE(tuples[i]), - /* If you would like, you could remove the _PyType_PreHeaderSize(&PyTuple_Type) + to make it so that the freelist entries actual memory is calculated */ - _PyType_PreHeaderSize(&PyTuple_Type) + _PyObject_VAR_SIZE(&PyTuple_Type, len)); + _PyObject_VAR_SIZE(&PyTuple_Type, len)); } } From 9abeba726ae0aa9fee0206d805b5ff5701ce2776 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 8 Apr 2026 02:49:08 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst new file mode 100644 index 00000000000000..d90e30b3d3fba8 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst @@ -0,0 +1 @@ +Repaired undercount of bytes in type-specific free lists reported by sys._debugmallocstats(). For types that participate in cyclic garbage collection, it was missing two pointers used by GC.