@@ -4655,12 +4655,7 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type, PyObject *dict
46554655 if (ctx -> add_weak ) {
46564656 assert ((type -> tp_flags & Py_TPFLAGS_MANAGED_WEAKREF ) == 0 );
46574657 type_add_flags (type , Py_TPFLAGS_MANAGED_WEAKREF );
4658- if (_PyType_IS_GC (type )) {
4659- type -> tp_weaklistoffset = MANAGED_WEAKREF_OFFSET ;
4660- }
4661- else {
4662- type -> tp_weaklistoffset = MANAGED_WEAKREF_OFFSET_NO_GC ;
4663- }
4658+ type -> tp_weaklistoffset = MANAGED_WEAKREF_OFFSET ;
46644659 }
46654660 if (ctx -> add_dict ) {
46664661 assert ((type -> tp_flags & Py_TPFLAGS_MANAGED_DICT ) == 0 );
@@ -8505,13 +8500,6 @@ overrides_hash(PyTypeObject *type)
85058500 return r ;
85068501}
85078502
8508- void
8509- PyObject_NoGC_Preheader_Del (void * op )
8510- {
8511- size_t presize = _PyType_PreHeaderSize (Py_TYPE (op ));
8512- PyObject_Free (((char * )op ) - presize );
8513- }
8514-
85158503static int
85168504inherit_slots (PyTypeObject * type , PyTypeObject * base )
85178505{
@@ -8689,21 +8677,7 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
86898677 if ((type -> tp_flags & Py_TPFLAGS_HAVE_GC ) ==
86908678 (base -> tp_flags & Py_TPFLAGS_HAVE_GC )) {
86918679 /* They agree about gc. */
8692-
8693- if ((type -> tp_flags & Py_TPFLAGS_PREHEADER ) &&
8694- type -> tp_free == NULL &&
8695- base -> tp_free == PyObject_Free ) {
8696- /* Because type has preheader fields, its
8697- * objects will be allocated with those fields
8698- * and it should be take in account when object
8699- * is freed, so we use special tp_free.
8700- */
8701- type -> tp_free = PyObject_NoGC_Preheader_Del ;
8702- }
8703- else {
8704- COPYSLOT (tp_free );
8705- }
8706-
8680+ COPYSLOT (tp_free );
87078681 }
87088682 else if ((type -> tp_flags & Py_TPFLAGS_HAVE_GC ) &&
87098683 type -> tp_free == NULL &&
@@ -8919,6 +8893,13 @@ type_ready_preheader(PyTypeObject *type)
89198893 type -> tp_name );
89208894 return -1 ;
89218895 }
8896+ if (!(type -> tp_flags & Py_TPFLAGS_HAVE_GC )) {
8897+ PyErr_Format (PyExc_SystemError ,
8898+ "type %s has the Py_TPFLAGS_MANAGED_DICT flag "
8899+ "but not Py_TPFLAGS_HAVE_GC flag" ,
8900+ type -> tp_name );
8901+ return -1 ;
8902+ }
89228903 type -> tp_dictoffset = -1 ;
89238904 }
89248905 if (type -> tp_flags & Py_TPFLAGS_MANAGED_WEAKREF ) {
@@ -8931,12 +8912,14 @@ type_ready_preheader(PyTypeObject *type)
89318912 type -> tp_name );
89328913 return -1 ;
89338914 }
8934- if (_PyType_IS_GC (type )) {
8935- type -> tp_weaklistoffset = MANAGED_WEAKREF_OFFSET ;
8936- }
8937- else {
8938- type -> tp_weaklistoffset = MANAGED_WEAKREF_OFFSET_NO_GC ;
8915+ if (!(type -> tp_flags & Py_TPFLAGS_HAVE_GC )) {
8916+ PyErr_Format (PyExc_SystemError ,
8917+ "type %s has the Py_TPFLAGS_MANAGED_WEAKREF flag "
8918+ "but not Py_TPFLAGS_HAVE_GC flag" ,
8919+ type -> tp_name );
8920+ return -1 ;
89398921 }
8922+ type -> tp_weaklistoffset = MANAGED_WEAKREF_OFFSET ;
89408923 }
89418924 return 0 ;
89428925}
0 commit comments