You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Visit the type of instance of heap types if tp_traverse is not implemented #85208
bpo-42972: [C API] Heap types (PyType_FromSpec) must fully implement the GC protocol
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-01-19.21:55:23.027>created_at=<Date2020-06-19.14:05:01.249>labels= ['interpreter-core', 'expert-C-API', '3.9', '3.10']
title='Visit the type of instance of heap types if tp_traverse is not implemented'updated_at=<Date2021-01-19.21:55:23.026>user='https://github.com/vstinner'
While reviewing changes of bpo-40077 "Convert static types to PyType_FromSpec()", I noticed that some static types don't implement tp_traverse.
The doc says:
Heap-allocated types (...) hold a reference to their type. Their traversal function must therefore either visit Py_TYPE(self), or delegate this responsibility by calling tp_traverse of another heap-allocated type (such as a heap-allocated superclass). If they do not, the type object may not be garbage-collected.
Activity
vstinner commentedon Jun 19, 2020
While reviewing changes of bpo-40077 "Convert static types to PyType_FromSpec()", I noticed that some static types don't implement tp_traverse.
The doc says:
https://docs.python.org/dev/c-api/typeobj.html#c.PyTypeObject.tp_traverse
Porting to 3.9 says:
https://docs.python.org/dev/whatsnew/3.9.html#changes-in-the-c-api
--
It seems like converting a static type to a heap allocated type requires to *add* a new tp_traverse function, if it wasn't the case.
Maybe we can provide a base tp_traverse implementation in the base object type: visit the type if it's a heap type?
See attached PR.
See bpo-35810 and bpo-40217 for more information.
vstinner commentedon Jan 12, 2021
I created a thread on python-dev:
"Heap types (PyType_FromSpec) must fully implement the GC protocol"
https://mail.python.org/archives/list/python-dev@python.org/thread/C4ILXGPKBJQYUN5YDMTJOEOX7RHOD4S3/
vstinner commentedon Jan 19, 2021
I created bpo-42972 instead.