summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorPeter Lazorchak <lazorchakp@gmail.com>2024-01-19 20:45:33 (GMT)
committerGitHub <noreply@github.com>2024-01-19 20:45:33 (GMT)
commitae2a25bf607410bb87d0b0c556adc7f56ec73fa9 (patch)
treebee004d849f369fac5ceb31cce6d649c2d7acc2c /Modules/_testcapimodule.c
parentffac6ac656f5ba591cddc88c990c2187a4d9a83d (diff)
downloadcpython-ae2a25bf607410bb87d0b0c556adc7f56ec73fa9.zip
cpython-ae2a25bf607410bb87d0b0c556adc7f56ec73fa9.tar.gz
cpython-ae2a25bf607410bb87d0b0c556adc7f56ec73fa9.tar.bz2
[3.12] Check for valid tp_version_tag in specializer (gh-89811) (gh-114216)
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 16eb881..48c8f92 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2530,6 +2530,32 @@ type_get_version(PyObject *self, PyObject *type)
return res;
}
+static PyObject *
+type_modified(PyObject *self, PyObject *type)
+{
+ if (!PyType_Check(type)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a type");
+ return NULL;
+ }
+ PyType_Modified((PyTypeObject *)type);
+ Py_RETURN_NONE;
+}
+
+// Circumvents standard version assignment machinery - use with caution and only on
+// short-lived heap types
+static PyObject *
+type_assign_specific_version_unsafe(PyObject *self, PyObject *args)
+{
+ PyTypeObject *type;
+ unsigned int version;
+ if (!PyArg_ParseTuple(args, "Oi:type_assign_specific_version_unsafe", &type, &version)) {
+ return NULL;
+ }
+ assert(!PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE));
+ type->tp_version_tag = version;
+ type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
+ Py_RETURN_NONE;
+}
static PyObject *
type_assign_version(PyObject *self, PyObject *type)
@@ -3357,6 +3383,9 @@ static PyMethodDef TestMethods[] = {
{"test_py_is_macros", test_py_is_macros, METH_NOARGS},
{"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_modified", type_modified, METH_O, PyDoc_STR("PyType_Modified")},
+ {"type_assign_specific_version_unsafe", type_assign_specific_version_unsafe, METH_VARARGS,
+ PyDoc_STR("forcefully assign 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},