summaryrefslogtreecommitdiff
path: root/test cases/python/9 extmodule limited api
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/python/9 extmodule limited api')
-rw-r--r--test cases/python/9 extmodule limited api/limited.c19
-rw-r--r--test cases/python/9 extmodule limited api/meson.build16
-rw-r--r--test cases/python/9 extmodule limited api/not_limited.c59
-rw-r--r--test cases/python/9 extmodule limited api/test.json8
4 files changed, 102 insertions, 0 deletions
diff --git a/test cases/python/9 extmodule limited api/limited.c b/test cases/python/9 extmodule limited api/limited.c
new file mode 100644
index 000000000..0d1c71820
--- /dev/null
+++ b/test cases/python/9 extmodule limited api/limited.c
@@ -0,0 +1,19 @@
+#include <Python.h>
+
+#ifndef Py_LIMITED_API
+#error Py_LIMITED_API must be defined.
+#elif Py_LIMITED_API != 0x03070000
+#error Wrong value for Py_LIMITED_API
+#endif
+
+static struct PyModuleDef limited_module = {
+ PyModuleDef_HEAD_INIT,
+ "limited_api_test",
+ NULL,
+ -1,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit_limited(void) {
+ return PyModule_Create(&limited_module);
+}
diff --git a/test cases/python/9 extmodule limited api/meson.build b/test cases/python/9 extmodule limited api/meson.build
new file mode 100644
index 000000000..68afc9699
--- /dev/null
+++ b/test cases/python/9 extmodule limited api/meson.build
@@ -0,0 +1,16 @@
+project('Python limited api', 'c',
+ default_options : ['buildtype=release', 'werror=true'])
+
+py_mod = import('python')
+py = py_mod.find_installation()
+
+ext_mod_limited = py.extension_module('limited',
+ 'limited.c',
+ limited_api: '3.7',
+ install: true,
+)
+
+ext_mod = py.extension_module('not_limited',
+ 'not_limited.c',
+ install: true,
+)
diff --git a/test cases/python/9 extmodule limited api/not_limited.c b/test cases/python/9 extmodule limited api/not_limited.c
new file mode 100644
index 000000000..105dbb80b
--- /dev/null
+++ b/test cases/python/9 extmodule limited api/not_limited.c
@@ -0,0 +1,59 @@
+#include <Python.h>
+#include <stdio.h>
+
+#ifdef Py_LIMITED_API
+#error Py_LIMITED_API must not be defined.
+#endif
+
+/* This function explicitly calls functions whose declaration is elided when
+ * Py_LIMITED_API is defined. This is to test that the linker is actually
+ * linking to the right version of the library on Windows. */
+static PyObject *meth_not_limited(PyObject *self, PyObject *args)
+{
+ PyObject *list;
+ Py_ssize_t size;
+
+ if (!PyArg_ParseTuple(args, "o", & list))
+ return NULL;
+
+ if (!PyList_Check(list)) {
+ PyErr_Format(PyExc_TypeError, "expected 'list'");
+ return NULL;
+ }
+
+ /* PyList_GET_SIZE and PyList_GET_ITEM are only available if Py_LIMITED_API
+ * is not defined. It seems likely that they will remain excluded from the
+ * limited API as their checked counterparts (PyList_GetSize and
+ * PyList_GetItem) are made available in that mode instead. */
+ size = PyList_GET_SIZE(list);
+ for(Py_ssize_t i = 0; i < size; ++i) {
+ PyObject *element = PyList_GET_ITEM(list, i);
+ if (element == NULL) {
+ return NULL;
+ }
+
+ if(PyObject_Print(element, stdout, Py_PRINT_RAW) == -1) {
+ return NULL;
+ }
+ }
+
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef not_limited_methods[] = {
+ { "not_limited", meth_not_limited, METH_VARARGS,
+ "Calls functions whose declaration is elided by Py_LIMITED_API" },
+ { NULL, NULL, 0, NULL }
+};
+
+static struct PyModuleDef not_limited_module = {
+ PyModuleDef_HEAD_INIT,
+ "not_limited_api_test",
+ NULL,
+ -1,
+ not_limited_methods
+};
+
+PyMODINIT_FUNC PyInit_not_limited(void) {
+ return PyModule_Create(&not_limited_module);
+}
diff --git a/test cases/python/9 extmodule limited api/test.json b/test cases/python/9 extmodule limited api/test.json
new file mode 100644
index 000000000..06a170623
--- /dev/null
+++ b/test cases/python/9 extmodule limited api/test.json
@@ -0,0 +1,8 @@
+{
+ "installed": [
+ {"type": "python_limited_lib", "file": "usr/@PYTHON_PLATLIB@/limited"},
+ {"type": "py_limited_implib", "file": "usr/@PYTHON_PLATLIB@/limited"},
+ {"type": "python_lib", "file": "usr/@PYTHON_PLATLIB@/not_limited"},
+ {"type": "py_implib", "file": "usr/@PYTHON_PLATLIB@/not_limited"}
+ ]
+}