summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-11-08 16:58:11 (GMT)
committerGitHub <noreply@github.com>2022-11-08 16:58:11 (GMT)
commitd45cc80452b11d5ffc5c9721f74a3e3df8ecad8b (patch)
treea68aceaa899e2d1404b4f5d8d747bb7a3023ce7b /Modules
parent4d5fcca273b24a5566f1507758e5aae60cdf8a98 (diff)
downloadcpython-d45cc80452b11d5ffc5c9721f74a3e3df8ecad8b.zip
cpython-d45cc80452b11d5ffc5c9721f74a3e3df8ecad8b.tar.gz
cpython-d45cc80452b11d5ffc5c9721f74a3e3df8ecad8b.tar.bz2
gh-98627: Add the _testsinglephase Module (gh-99039)
This makes it more clear that a given test is definitely testing against a single-phase init (legacy) extension module. The new module is a companion to _testmultiphase. https://github.com/python/cpython/issues/98627
Diffstat (limited to 'Modules')
-rw-r--r--Modules/Setup1
-rw-r--r--Modules/Setup.stdlib.in1
-rw-r--r--Modules/_testsinglephase.c78
3 files changed, 80 insertions, 0 deletions
diff --git a/Modules/Setup b/Modules/Setup
index 8fe7951..e3a8297 100644
--- a/Modules/Setup
+++ b/Modules/Setup
@@ -291,6 +291,7 @@ PYTHONPATH=$(COREPYTHONPATH)
#_testcapi _testcapimodule.c
#_testimportmultiple _testimportmultiple.c
#_testmultiphase _testmultiphase.c
+#_testsinglephase _testsinglephase.c
# ---
# Uncommenting the following line tells makesetup that all following modules
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index ac8959e..74d2222 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -175,6 +175,7 @@
*shared*
@MODULE__TESTIMPORTMULTIPLE_TRUE@_testimportmultiple _testimportmultiple.c
@MODULE__TESTMULTIPHASE_TRUE@_testmultiphase _testmultiphase.c
+@MODULE__TESTMULTIPHASE_TRUE@_testsinglephase _testsinglephase.c
@MODULE__CTYPES_TEST_TRUE@_ctypes_test _ctypes/_ctypes_test.c
# Limited API template modules; must be built as shared modules.
diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c
new file mode 100644
index 0000000..3bfe159
--- /dev/null
+++ b/Modules/_testsinglephase.c
@@ -0,0 +1,78 @@
+
+/* Testing module for single-phase initialization of extension modules
+ */
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
+#include "Python.h"
+#include "pycore_namespace.h" // _PyNamespace_New()
+
+
+/* Function of two integers returning integer */
+
+PyDoc_STRVAR(testexport_foo_doc,
+"foo(i,j)\n\
+\n\
+Return the sum of i and j.");
+
+static PyObject *
+testexport_foo(PyObject *self, PyObject *args)
+{
+ long i, j;
+ long res;
+ if (!PyArg_ParseTuple(args, "ll:foo", &i, &j))
+ return NULL;
+ res = i + j;
+ return PyLong_FromLong(res);
+}
+
+
+static PyMethodDef TestMethods[] = {
+ {"foo", testexport_foo, METH_VARARGS,
+ testexport_foo_doc},
+ {NULL, NULL} /* sentinel */
+};
+
+
+static struct PyModuleDef _testsinglephase = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "_testsinglephase",
+ .m_doc = PyDoc_STR("Test module _testsinglephase (main)"),
+ .m_size = -1, // no module state
+ .m_methods = TestMethods,
+};
+
+
+PyMODINIT_FUNC
+PyInit__testsinglephase(void)
+{
+ PyObject *module = PyModule_Create(&_testsinglephase);
+ if (module == NULL) {
+ return NULL;
+ }
+
+ /* Add an exception type */
+ PyObject *temp = PyErr_NewException("_testsinglephase.error", NULL, NULL);
+ if (temp == NULL) {
+ goto error;
+ }
+ if (PyModule_AddObject(module, "error", temp) != 0) {
+ Py_DECREF(temp);
+ goto error;
+ }
+
+ if (PyModule_AddIntConstant(module, "int_const", 1969) != 0) {
+ goto error;
+ }
+
+ if (PyModule_AddStringConstant(module, "str_const", "something different") != 0) {
+ goto error;
+ }
+
+ return module;
+
+error:
+ Py_DECREF(module);
+ return NULL;
+}