From 4866a8bb75b1037b783ac37af164f853190b0112 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Wed, 15 Apr 2026 23:45:27 +0100 Subject: [PATCH] gh-146462: add dict introspection debug offsets --- Include/internal/pycore_debug_offsets.h | 14 ++++++++++++++ .../2026-04-15-12-00-00.gh-issue-146462.1YfK6v.rst | 3 +++ .../_remote_debugging/debug_offsets_validation.h | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-04-15-12-00-00.gh-issue-146462.1YfK6v.rst diff --git a/Include/internal/pycore_debug_offsets.h b/Include/internal/pycore_debug_offsets.h index c166f963da4f66..fcfa86e8bb690d 100644 --- a/Include/internal/pycore_debug_offsets.h +++ b/Include/internal/pycore_debug_offsets.h @@ -158,8 +158,16 @@ typedef struct _Py_DebugOffsets { uint64_t tp_name; uint64_t tp_repr; uint64_t tp_flags; + uint64_t tp_basicsize; + uint64_t tp_dictoffset; } type_object; + // PyHeapTypeObject offset; + struct _heap_type_object { + uint64_t size; + uint64_t ht_cached_keys; + } heap_type_object; + // PyTuple object offset; struct _tuple_object { uint64_t size; @@ -329,6 +337,12 @@ typedef struct _Py_DebugOffsets { .tp_name = offsetof(PyTypeObject, tp_name), \ .tp_repr = offsetof(PyTypeObject, tp_repr), \ .tp_flags = offsetof(PyTypeObject, tp_flags), \ + .tp_basicsize = offsetof(PyTypeObject, tp_basicsize), \ + .tp_dictoffset = offsetof(PyTypeObject, tp_dictoffset), \ + }, \ + .heap_type_object = { \ + .size = sizeof(PyHeapTypeObject), \ + .ht_cached_keys = offsetof(PyHeapTypeObject, ht_cached_keys), \ }, \ .tuple_object = { \ .size = sizeof(PyTupleObject), \ diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-15-12-00-00.gh-issue-146462.1YfK6v.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-15-12-00-00.gh-issue-146462.1YfK6v.rst new file mode 100644 index 00000000000000..44019b7562a344 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-15-12-00-00.gh-issue-146462.1YfK6v.rst @@ -0,0 +1,3 @@ +Added ``PyTypeObject.tp_basicsize``, ``PyTypeObject.tp_dictoffset``, and +``PyHeapTypeObject.ht_cached_keys`` offsets to :c:type:`!_Py_DebugOffsets` to +support version-independent read-only dict introspection tools. diff --git a/Modules/_remote_debugging/debug_offsets_validation.h b/Modules/_remote_debugging/debug_offsets_validation.h index 32800e767b3169..e782edc0c63d82 100644 --- a/Modules/_remote_debugging/debug_offsets_validation.h +++ b/Modules/_remote_debugging/debug_offsets_validation.h @@ -31,7 +31,7 @@ #define FIELD_SIZE(type, member) sizeof(((type *)0)->member) enum { - PY_REMOTE_DEBUG_OFFSETS_TOTAL_SIZE = 840, + PY_REMOTE_DEBUG_OFFSETS_TOTAL_SIZE = 872, PY_REMOTE_ASYNC_DEBUG_OFFSETS_TOTAL_SIZE = 104, };