Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Isolate tp_mro.
  • Loading branch information
ericsnowcurrently committed May 2, 2023
commit 2e28be59e408ec899746c2d70e04dc84deb8b6b4
1 change: 1 addition & 0 deletions Modules/_abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_object.h" // _PyType_GetSubclasses()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_typeobject.h" // _PyType_GetMRO()
#include "clinic/_abc.c.h"

/*[clinic input]
Expand Down
22 changes: 21 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ clear_tp_bases(PyTypeObject *self)
static inline PyObject *
lookup_tp_mro(PyTypeObject *self)
{
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
PyInterpreterState *interp = _PyInterpreterState_GET();
static_builtin_state *state = _PyStaticType_GetState(interp, self);
assert(state != NULL);
return state->tp_mro;
}
return self->tp_mro;
}

Expand All @@ -254,12 +260,26 @@ _PyType_GetMRO(PyTypeObject *self)
static inline void
set_tp_mro(PyTypeObject *self, PyObject *mro)
{
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
PyInterpreterState *interp = _PyInterpreterState_GET();
static_builtin_state *state = _PyStaticType_GetState(interp, self);
assert(state != NULL);
state->tp_mro = mro;
return;
}
self->tp_mro = mro;
}

static inline void
clear_tp_mro(PyTypeObject *self)
{
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
PyInterpreterState *interp = _PyInterpreterState_GET();
static_builtin_state *state = _PyStaticType_GetState(interp, self);
assert(state != NULL);
Py_CLEAR(state->tp_mro);
return;
}
Py_CLEAR(self->tp_mro);
}

Expand Down Expand Up @@ -4719,11 +4739,11 @@ clear_static_type_objects(PyInterpreterState *interp, PyTypeObject *type)
{
if (_Py_IsMainInterpreter(interp)) {
clear_tp_dict(type);
clear_tp_mro(type);
Py_CLEAR(type->tp_cache);
}
else {
clear_tp_bases(type);
clear_tp_mro(type);
}
clear_static_tp_subclasses(type);
}
Expand Down