summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorPeter Lazorchak <lazorchakp@gmail.com>2024-01-11 05:33:05 (GMT)
committerGitHub <noreply@github.com>2024-01-11 05:33:05 (GMT)
commitf653caa5a88d3b5027a8f286ff3a3ccd9e6fe4ed (patch)
treee75ee87059e89705ec510e1070181aab5bc1a13d /Modules
parentc65ae26f2b46ca616a7ca000bbfcdf63b9bdd779 (diff)
downloadcpython-f653caa5a88d3b5027a8f286ff3a3ccd9e6fe4ed.zip
cpython-f653caa5a88d3b5027a8f286ff3a3ccd9e6fe4ed.tar.gz
cpython-f653caa5a88d3b5027a8f286ff3a3ccd9e6fe4ed.tar.bz2
gh-89811: Check for valid tp_version_tag in specializer (GH-113558)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 398570f..a0b21b7 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2409,6 +2409,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)
@@ -3342,6 +3368,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},