diff options
author | Leo Singer <leo.singer@ligo.org> | 2022-01-13 13:09:23 -0500 |
---|---|---|
committer | Leo Singer <leo.singer@ligo.org> | 2022-01-13 18:55:02 -0500 |
commit | a61474e88112c361563bbb134708da2fb627e93e (patch) | |
tree | 78c63be3a3b32cd4ea9fa9db800722bfcc52d421 | |
parent | 8b70732e81602f64b31fb2a3b25c9741ce0d2886 (diff) | |
download | numpy-a61474e88112c361563bbb134708da2fb627e93e.tar.gz |
TST: Test building third party C extensions with Py_LIMITED_API
Fixes #13784.
-rw-r--r-- | numpy/core/tests/examples/example_limited_api.c | 22 | ||||
-rw-r--r-- | numpy/core/tests/examples/setup.py | 12 |
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) |