gh-134786: Py_TPFLAGS_MANAGED_WEAKREF implies Py_TPFLAGS_HAVE_GC too and force checking of its presence #135863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If we allow to use Py_TPFLAGS_MANAGED_WEAKREF without Py_TPFLAGS_HAVE_GC then we should change a way of calculation weakref list offsets.
cpython/Include/internal/pycore_object.h
Lines 804 to 847 in bda1218
As I understand from #95245 the main idea of moving dict pointer and weakref pointer to the preheader is to simplify access to them.
Another note: typeobject.c/compatible_for_assignment is checking Py_TPFLAGS_PREHEADER for lhs and rhs types. But Py_TPFLAGS_PREHEADER is a
Py_TPFLAGS_MANAGED_WEAKREF | Py_TPFLAGS_MANAGED_DICT
and might be true if one object is supporting GC and other not and we should handle this complicated case.cpython/Objects/typeobject.c
Lines 7291 to 7296 in bda1218
So, I propose to change requirements for Py_TPFLAGS_MANAGED_WEAKREF and also force checking of having Py_TPFLAGS_HAVE_GC set for Py_TPFLAGS_MANAGED_WEAKREF and Py_TPFLAGS_MANAGED_DICT.
📚 Documentation preview 📚: https://cpython-previews--135863.org.readthedocs.build/