-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
Bug report
Bug description:
The dump_stack() function, used when tracing micro-op execution, crashes if a PyDictKeysObject* pointer is on the stack.
Despite the name, PyDictKeysObject is not a PyObject.
Introduced in f978fb4
I think the best fix would be arrange the fields (at least in the debug build) of PyDictKeysObject such that the dk_kind field is placed in the least significant byte of the ob_type field of PyObject and change DictKeysKind so that none of its values have the low 2 bits set to 0.
Then dump_stack can check the low bits of the ob_type to see whether the "object" is a PyObject or a PyDictKeysObject.
Looking forward, we expect to have an unused value for the low bits in PyStackRef, so we could assign them the meaning "not a Python object".
This would add overhead when pushing and popping PyDictKeysObjects, but would make introspection a lot more robust.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response