Skip to content

Commit

Permalink
Re-run most of type_ready() under each interpreter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed May 2, 2023
1 parent 05711e6 commit 9937406
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7075,7 +7075,7 @@ type_ready_add_subclasses(PyTypeObject *type)
// Set tp_new and the "__new__" key in the type dictionary.
// Use the Py_TPFLAGS_DISALLOW_INSTANTIATION flag.
static int
type_ready_set_new(PyTypeObject *type)
type_ready_set_new(PyTypeObject *type, int rerunbuiltin)
{
PyTypeObject *base = type->tp_base;
/* The condition below could use some explanation.
Expand All @@ -7097,10 +7097,12 @@ type_ready_set_new(PyTypeObject *type)

if (!(type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION)) {
if (type->tp_new != NULL) {
// If "__new__" key does not exists in the type dictionary,
// set it to tp_new_wrapper().
if (add_tp_new_wrapper(type) < 0) {
return -1;
if (!rerunbuiltin || base == NULL || type->tp_new != base->tp_new) {
// If "__new__" key does not exists in the type dictionary,
// set it to tp_new_wrapper().
if (add_tp_new_wrapper(type) < 0) {
return -1;
}
}
}
else {
Expand Down Expand Up @@ -7174,7 +7176,7 @@ type_ready_post_checks(PyTypeObject *type)


static int
type_ready(PyTypeObject *type)
type_ready(PyTypeObject *type, int rerunbuiltin)
{
_PyObject_ASSERT((PyObject *)type,
(type->tp_flags & Py_TPFLAGS_READYING) == 0);
Expand Down Expand Up @@ -7203,29 +7205,33 @@ type_ready(PyTypeObject *type)
if (type_ready_mro(type) < 0) {
goto error;
}
if (type_ready_set_new(type) < 0) {
if (type_ready_set_new(type, rerunbuiltin) < 0) {
goto error;
}
if (type_ready_fill_dict(type) < 0) {
goto error;
}
if (type_ready_inherit(type) < 0) {
goto error;
}
if (type_ready_preheader(type) < 0) {
goto error;
if (!rerunbuiltin) {
if (type_ready_inherit(type) < 0) {
goto error;
}
if (type_ready_preheader(type) < 0) {
goto error;
}
}
if (type_ready_set_hash(type) < 0) {
goto error;
}
if (type_ready_add_subclasses(type) < 0) {
goto error;
}
if (type_ready_managed_dict(type) < 0) {
goto error;
}
if (type_ready_post_checks(type) < 0) {
goto error;
if (!rerunbuiltin) {
if (type_ready_managed_dict(type) < 0) {
goto error;
}
if (type_ready_post_checks(type) < 0) {
goto error;
}
}

/* All done -- set the ready flag */
Expand Down Expand Up @@ -7253,7 +7259,7 @@ PyType_Ready(PyTypeObject *type)
type->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE;
}

return type_ready(type);
return type_ready(type, 0);
}

int
Expand All @@ -7271,16 +7277,7 @@ _PyStaticType_InitBuiltin(PyInterpreterState *interp, PyTypeObject *self)
assert(!ismain);
assert(self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN);
assert(self->tp_flags & Py_TPFLAGS_VALID_VERSION_TAG);

static_builtin_state_init(interp, self);

/* We must explicitly set these for subinterpreters.
tp_subclasses is set lazily. */
type_ready_set_dict(self);
type_ready_set_bases(self);
type_ready_mro(self);
assert(_PyType_CheckConsistency(self));
return 0;
return type_ready(self, 1);
}

assert(ismain);
Expand All @@ -7294,7 +7291,7 @@ _PyStaticType_InitBuiltin(PyInterpreterState *interp, PyTypeObject *self)

static_builtin_state_init(interp, self);

int res = type_ready(self);
int res = type_ready(self, 0);
if (res < 0) {
static_builtin_state_clear(interp, self);
}
Expand Down

0 comments on commit 9937406

Please sign in to comment.