summaryrefslogtreecommitdiffstats
path: root/Modules/_testmultiphase.c
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2022-02-11 11:25:25 (GMT)
committerGitHub <noreply@github.com>2022-02-11 11:25:25 (GMT)
commit8b8673fe940c4ebc4512bff5af180b66def3d1ae (patch)
tree97ea957663ed8fe28fe0bc9a35b37ff134cb6e70 /Modules/_testmultiphase.c
parent1124ab6d1d15dc5058e03b63fd1d95e6f1009cc3 (diff)
downloadcpython-8b8673fe940c4ebc4512bff5af180b66def3d1ae.zip
cpython-8b8673fe940c4ebc4512bff5af180b66def3d1ae.tar.gz
cpython-8b8673fe940c4ebc4512bff5af180b66def3d1ae.tar.bz2
[3.10] bpo-46433: _PyType_GetModuleByDef: handle static types in MRO (GH-30696) (GH-31262)
(cherry picked from commit 0ef08530124c5ca13a9394f4ac18bee8e6c66409)
Diffstat (limited to 'Modules/_testmultiphase.c')
-rw-r--r--Modules/_testmultiphase.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
index e0ed77d..58282ce 100644
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -122,6 +122,8 @@ static PyType_Spec Example_Type_spec = {
static PyModuleDef def_meth_state_access;
+static PyModuleDef def_nonmodule;
+static PyModuleDef def_nonmodule_with_methods;
/*[clinic input]
_testmultiphase.StateAccessType.get_defining_module
@@ -150,6 +152,24 @@ _testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *
}
/*[clinic input]
+_testmultiphase.StateAccessType.getmodulebydef_bad_def
+
+ cls: defining_class
+
+Test that result of _PyType_GetModuleByDef with a bad def is NULL.
+[clinic start generated code]*/
+
+static PyObject *
+_testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(StateAccessTypeObject *self,
+ PyTypeObject *cls)
+/*[clinic end generated code: output=64509074dfcdbd31 input=906047715ee293cd]*/
+{
+ _PyType_GetModuleByDef(Py_TYPE(self), &def_nonmodule); // should raise
+ assert(PyErr_Occurred());
+ return NULL;
+}
+
+/*[clinic input]
_testmultiphase.StateAccessType.increment_count_clinic
cls: defining_class
@@ -245,6 +265,7 @@ _testmultiphase_StateAccessType_get_count_impl(StateAccessTypeObject *self,
static PyMethodDef StateAccessType_methods[] = {
_TESTMULTIPHASE_STATEACCESSTYPE_GET_DEFINING_MODULE_METHODDEF
+ _TESTMULTIPHASE_STATEACCESSTYPE_GETMODULEBYDEF_BAD_DEF_METHODDEF
_TESTMULTIPHASE_STATEACCESSTYPE_GET_COUNT_METHODDEF
_TESTMULTIPHASE_STATEACCESSTYPE_INCREMENT_COUNT_CLINIC_METHODDEF
{
@@ -433,9 +454,6 @@ PyInit__testmultiphase(PyObject *spec)
/**** Importing a non-module object ****/
-static PyModuleDef def_nonmodule;
-static PyModuleDef def_nonmodule_with_methods;
-
/* Create a SimpleNamespace(three=3) */
static PyObject*
createfunc_nonmodule(PyObject *spec, PyModuleDef *def)