44#include "pycore_abstract.h" // _PySequence_IterSearch()
55#include "pycore_call.h" // _PyObject_VectorcallTstate()
66#include "pycore_code.h" // CO_FAST_FREE
7+ #include "pycore_descrobject.h" // _PyMember_GetOffset()
78#include "pycore_dict.h" // _PyDict_KeysSize()
89#include "pycore_function.h" // _PyFunction_GetVersionForCurrentState()
910#include "pycore_interpframe.h" // _PyInterpreterFrame
@@ -2578,7 +2579,7 @@ traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
25782579 mp = _PyHeapType_GET_MEMBERS ((PyHeapTypeObject * )type );
25792580 for (i = 0 ; i < n ; i ++ , mp ++ ) {
25802581 if (mp -> type == Py_T_OBJECT_EX ) {
2581- char * addr = ( char * ) self + mp -> offset ;
2582+ void * addr = _PyMember_GetOffset ( self , mp ) ;
25822583 PyObject * obj = * (PyObject * * )addr ;
25832584 if (obj != NULL ) {
25842585 int err = visit (obj , arg );
@@ -2653,7 +2654,7 @@ clear_slots(PyTypeObject *type, PyObject *self)
26532654 mp = _PyHeapType_GET_MEMBERS ((PyHeapTypeObject * )type );
26542655 for (i = 0 ; i < n ; i ++ , mp ++ ) {
26552656 if (mp -> type == Py_T_OBJECT_EX && !(mp -> flags & Py_READONLY )) {
2656- char * addr = ( char * ) self + mp -> offset ;
2657+ void * addr = _PyMember_GetOffset ( self , mp ) ;
26572658 PyObject * obj = * (PyObject * * )addr ;
26582659 if (obj != NULL ) {
26592660 * (PyObject * * )addr = NULL ;
@@ -4641,7 +4642,11 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type, PyObject *dict
46414642 if (et -> ht_slots != NULL ) {
46424643 PyMemberDef * mp = _PyHeapType_GET_MEMBERS (et );
46434644 Py_ssize_t nslot = PyTuple_GET_SIZE (et -> ht_slots );
4644- if (ctx -> base -> tp_itemsize != 0 ) {
4645+ int after_items = (ctx -> base -> tp_itemsize != 0 &&
4646+ !(ctx -> base -> tp_flags & Py_TPFLAGS_ITEMS_AT_END ));
4647+ if (ctx -> base -> tp_itemsize != 0 &&
4648+ !(ctx -> base -> tp_flags & Py_TPFLAGS_TUPLE_SUBCLASS ))
4649+ {
46454650 PyErr_Format (PyExc_TypeError ,
46464651 "arbitrary __slots__ not supported for subtype of '%s'" ,
46474652 ctx -> base -> tp_name );
@@ -4655,6 +4660,9 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type, PyObject *dict
46554660 }
46564661 mp -> type = Py_T_OBJECT_EX ;
46574662 mp -> offset = slotoffset ;
4663+ if (after_items ) {
4664+ mp -> flags |= _Py_AFTER_ITEMS ;
4665+ }
46584666
46594667 /* __dict__ and __weakref__ are already filtered out */
46604668 assert (strcmp (mp -> name , "__dict__" ) != 0 );
0 commit comments