Skip to content

Commit

Permalink
Split up type_ready_set_bases().
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed May 31, 2023
1 parent 7be667d commit fe12a90
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6996,12 +6996,8 @@ type_ready_pre_checks(PyTypeObject *type)


static int
type_ready_set_bases(PyTypeObject *type)
type_ready_set_base(PyTypeObject *type)
{
if (lookup_tp_bases(type) != NULL) {
return 0;
}

/* Initialize tp_base (defaults to BaseObject unless that's us) */
PyTypeObject *base = type->tp_base;
if (base == NULL && type != &PyBaseObject_Type) {
Expand All @@ -7025,18 +7021,34 @@ type_ready_set_bases(PyTypeObject *type)
}
}

return 0;
}

static int
type_ready_set_type(PyTypeObject *type)
{
/* Initialize ob_type if NULL. This means extensions that want to be
compilable separately on Windows can call PyType_Ready() instead of
initializing the ob_type field of their type objects. */
/* The test for base != NULL is really unnecessary, since base is only
NULL when type is &PyBaseObject_Type, and we know its ob_type is
not NULL (it's initialized to &PyType_Type). But coverity doesn't
know that. */
PyTypeObject *base = type->tp_base;
if (Py_IS_TYPE(type, NULL) && base != NULL) {
Py_SET_TYPE(type, Py_TYPE(base));
}

/* Initialize tp_bases */
return 0;
}

static int
type_ready_set_bases(PyTypeObject *type)
{
if (lookup_tp_bases(type) != NULL) {
return 0;
}

PyObject *bases = lookup_tp_bases(type);
if (bases == NULL) {
PyTypeObject *base = type->tp_base;
Expand Down Expand Up @@ -7446,6 +7458,12 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
if (type_ready_set_dict(type) < 0) {
goto error;
}
if (type_ready_set_base(type) < 0) {
goto error;
}
if (type_ready_set_type(type) < 0) {
goto error;
}
if (type_ready_set_bases(type) < 0) {
goto error;
}
Expand Down

0 comments on commit fe12a90

Please sign in to comment.