mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
[3.12] gh-105020: Share tp_bases and tp_mro Between Interpreters For All Static Builtin Types (gh-105115) (gh-105124)
In gh-103912 we added tp_bases and tp_mro to each PyInterpreterState.types.builtins entry. However, doing so ignored the fact that both PyTypeObject fields are public API, and not documented as internal (as opposed to tp_subclasses). We address that here by reverting back to shared objects, making them immortal in the process.
(cherry picked from commit 7be667d
)
Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
This commit is contained in:
parent
83c7386cee
commit
c38ceb032d
7 changed files with 26544 additions and 26462 deletions
|
@ -2606,6 +2606,27 @@ type_assign_version(PyObject *self, PyObject *type)
|
|||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
type_get_tp_bases(PyObject *self, PyObject *type)
|
||||
{
|
||||
PyObject *bases = ((PyTypeObject *)type)->tp_bases;
|
||||
if (bases == NULL) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return Py_NewRef(bases);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
type_get_tp_mro(PyObject *self, PyObject *type)
|
||||
{
|
||||
PyObject *mro = ((PyTypeObject *)type)->tp_mro;
|
||||
if (mro == NULL) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return Py_NewRef(mro);
|
||||
}
|
||||
|
||||
|
||||
// Test PyThreadState C API
|
||||
static PyObject *
|
||||
test_tstate_capi(PyObject *self, PyObject *Py_UNUSED(args))
|
||||
|
@ -3361,6 +3382,8 @@ static PyMethodDef TestMethods[] = {
|
|||
{"test_py_is_funcs", test_py_is_funcs, METH_NOARGS},
|
||||
{"type_get_version", type_get_version, METH_O, PyDoc_STR("type->tp_version_tag")},
|
||||
{"type_assign_version", type_assign_version, METH_O, PyDoc_STR("PyUnstable_Type_AssignVersionTag")},
|
||||
{"type_get_tp_bases", type_get_tp_bases, METH_O},
|
||||
{"type_get_tp_mro", type_get_tp_mro, METH_O},
|
||||
{"test_tstate_capi", test_tstate_capi, METH_NOARGS, NULL},
|
||||
{"frame_getlocals", frame_getlocals, METH_O, NULL},
|
||||
{"frame_getglobals", frame_getglobals, METH_O, NULL},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue