@@ -3488,11 +3488,11 @@ get_bases_tuple(PyObject *bases_in, PyType_Spec *spec)
34883488}
34893489
34903490static inline int
3491- check_basicsize_includes_size_and_offsets (PyTypeObject * type )
3491+ type_check_basicsize_includes_size_and_offsets (PyTypeObject * type )
34923492{
34933493 if (type -> tp_alloc != PyType_GenericAlloc ) {
34943494 // Custom allocators can ignore tp_basicsize
3495- return 1 ;
3495+ return 0 ;
34963496 }
34973497 Py_ssize_t max = (Py_ssize_t )type -> tp_basicsize ;
34983498
@@ -3501,30 +3501,30 @@ check_basicsize_includes_size_and_offsets(PyTypeObject* type)
35013501 "tp_basicsize for type '%s' (%d) is too small for base '%s' (%d)" ,
35023502 type -> tp_name , type -> tp_basicsize ,
35033503 type -> tp_base -> tp_name , type -> tp_base -> tp_basicsize );
3504- return 0 ;
3504+ return -1 ;
35053505 }
35063506 if (type -> tp_weaklistoffset + (Py_ssize_t )sizeof (PyObject * ) > max ) {
35073507 PyErr_Format (PyExc_TypeError ,
35083508 "weaklist offset %d is out of bounds for type '%s' (tp_basicsize = %d)" ,
35093509 type -> tp_weaklistoffset ,
35103510 type -> tp_name , type -> tp_basicsize );
3511- return 0 ;
3511+ return -1 ;
35123512 }
35133513 if (type -> tp_dictoffset + (Py_ssize_t )sizeof (PyObject * ) > max ) {
35143514 PyErr_Format (PyExc_TypeError ,
35153515 "dict offset %d is out of bounds for type '%s' (tp_basicsize = %d)" ,
35163516 type -> tp_dictoffset ,
35173517 type -> tp_name , type -> tp_basicsize );
3518- return 0 ;
3518+ return -1 ;
35193519 }
35203520 if (type -> tp_vectorcall_offset + (Py_ssize_t )sizeof (vectorcallfunc * ) > max ) {
35213521 PyErr_Format (PyExc_TypeError ,
35223522 "vectorcall offset %d is out of bounds for type '%s' (tp_basicsize = %d)" ,
35233523 type -> tp_vectorcall_offset ,
35243524 type -> tp_name , type -> tp_basicsize );
3525- return 0 ;
3525+ return -1 ;
35263526 }
3527- return 1 ;
3527+ return 0 ;
35283528}
35293529
35303530PyObject *
@@ -3825,10 +3825,6 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
38253825 goto finally ;
38263826 }
38273827
3828- if (!check_basicsize_includes_size_and_offsets (type )) {
3829- goto finally ;
3830- }
3831-
38323828 if (type -> tp_doc ) {
38333829 PyObject * __doc__ = PyUnicode_FromString (_PyType_DocWithoutSignature (type -> tp_name , type -> tp_doc ));
38343830 if (!__doc__ ) {
@@ -6869,6 +6865,9 @@ type_ready(PyTypeObject *type)
68696865 if (type_ready_managed_dict (type ) < 0 ) {
68706866 return -1 ;
68716867 }
6868+ if (type_check_basicsize_includes_size_and_offsets (type ) < 0 ) {
6869+ return -1 ;
6870+ }
68726871 if (type_ready_post_checks (type ) < 0 ) {
68736872 return -1 ;
68746873 }
0 commit comments