diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-05-31 00:13:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-31 00:13:35 (GMT) |
commit | 7be667dfafa2465df6342d72dca9c1f82dd830d0 (patch) | |
tree | 6fb8852fb71d0348327d0d79bf152acb4fddd03d /Modules/_testcapimodule.c | |
parent | 26e7bbf66e93ee7c94b6e007ec7b2d769c2ced92 (diff) | |
download | cpython-7be667dfafa2465df6342d72dca9c1f82dd830d0.zip cpython-7be667dfafa2465df6342d72dca9c1f82dd830d0.tar.gz cpython-7be667dfafa2465df6342d72dca9c1f82dd830d0.tar.bz2 |
gh-105020: Share tp_bases and tp_mro Between Interpreters For All Static Builtin Types (gh-105115)
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.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index aff09aa..66c1cba 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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}, |