8000 TST: Test building third party C extensions with Py_LIMITED_API · numpy/numpy@52b2da3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52b2da3

Browse files
committed
TST: Test building third party C extensions with Py_LIMITED_API
Fixes #13784.
1 parent 53e4f63 commit 52b2da3

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Test that third-party extensions that use the Numpy C API can be built with
3+
* the limited Python C API (see https://docs.python.org/3/c-api/stable.html).
4+
*/
5+
6+
#define Py_LIMITED_API 0x03060000
7+
8+
#include <Python.h>
9+
#include <numpy/arrayobject.h>
10+
#include <numpy/ufuncobject.h>
11+
12+
static PyModuleDef moduledef = {
13+
.m_base = PyModuleDef_HEAD_INIT,
14+
.m_name = "example_limited_api"
15+
};
16+
17+
PyMODINIT_FUNC PyInit_example_limited_api(void)
18+
{
19+
import_array();
20+
import_umath();
21+
return PyModule_Create(&moduledef);
22+
}

numpy/core/tests/examples/setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
from setuptools.extension import Extension
1010
import os
1111

12+
include_dirs = [np.get_include()]
1213
macros = [("NPY_NO_DEPRECATED_API", 0)]
1314

1415
checks = Extension(
1516
"checks",
1617
sources=[os.path.join('.', "checks.pyx")],
17-
include_dirs=[np.get_include()],
18+
include_dirs=include_dirs,
1819
define_macros=macros,
1920
)
2021

21-
extensions = [checks]
22+
example_limited_api = Extension(
23+
"example_limited_api",
24+
sources=[os.path.join('.', "example_limited_api.c")],
25+
include_dirs=include_dirs,
26+
define_macros=macros,
27+
)
28+
29+
extensions = [checks, example_limited_api]
2230

2331
setup(
2432
ext_modules=cythonize(extensions)

0 commit comments

Comments
 (0)
0