summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/tests/examples/example_limited_api.c22
-rw-r--r--numpy/core/tests/examples/setup.py12
2 files changed, 32 insertions, 2 deletions
diff --git a/numpy/core/tests/examples/example_limited_api.c b/numpy/core/tests/examples/example_limited_api.c
new file mode 100644
index 000000000..e811800b4
--- /dev/null
+++ b/numpy/core/tests/examples/example_limited_api.c
@@ -0,0 +1,22 @@
+/*
+ * Test that third-party extensions that use the Numpy C API can be built with
+ * the limited Python C API (see https://docs.python.org/3/c-api/stable.html).
+ */
+
+#define Py_LIMITED_API 0x03060000
+
+#include <Python.h>
+#include <numpy/arrayobject.h>
+#include <numpy/ufuncobject.h>
+
+static PyModuleDef moduledef = {
+ .m_base = PyModuleDef_HEAD_INIT,
+ .m_name = "example_limited_api"
+};
+
+PyMODINIT_FUNC PyInit_example_limited_api(void)
+{
+ import_array();
+ import_umath();
+ return PyModule_Create(&moduledef);
+}
diff --git a/numpy/core/tests/examples/setup.py b/numpy/core/tests/examples/setup.py
index 6e34aa778..6ec0b4197 100644
--- a/numpy/core/tests/examples/setup.py
+++ b/numpy/core/tests/examples/setup.py
@@ -9,16 +9,24 @@ from Cython.Build import cythonize
from setuptools.extension import Extension
import os
+include_dirs = [np.get_include()]
macros = [("NPY_NO_DEPRECATED_API", 0)]
checks = Extension(
"checks",
sources=[os.path.join('.', "checks.pyx")],
- include_dirs=[np.get_include()],
+ include_dirs=include_dirs,
define_macros=macros,
)
-extensions = [checks]
+example_limited_api = Extension(
+ "example_limited_api",
+ sources=[os.path.join('.', "example_limited_api.c")],
+ include_dirs=include_dirs,
+ define_macros=macros,
+)
+
+extensions = [checks, example_limited_api]
setup(
ext_modules=cythonize(extensions)