Skip to content

Commit 9235755

Browse files
authored
Merge pull request numpy#26985 from seberg/issue-26756
BUG: Add object cast to avoid warning with limited API
2 parents 495fe43 + 24fdf13 commit 9235755

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

numpy/_core/include/numpy/dtype_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ typedef PyArray_DTypeMeta *(PyArrayDTypeMeta_CommonDType)(
449449

450450
static inline PyArray_DTypeMeta *
451451
NPY_DT_NewRef(PyArray_DTypeMeta *o) {
452-
Py_INCREF(o);
452+
Py_INCREF((PyObject *)o);
453453
return o;
454454
}
455455

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if Py_LIMITED_API != PY_VERSION_HEX & 0xffff0000
2+
# error "Py_LIMITED_API not defined to Python major+minor version"
3+
#endif
4+
5+
#include <Python.h>
6+
#include <numpy/arrayobject.h>
7+
#include <numpy/ufuncobject.h>
8+
9+
static PyModuleDef moduledef = {
10+
.m_base = PyModuleDef_HEAD_INIT,
11+
.m_name = "limited_api_latest"
12+
};
13+
14+
PyMODINIT_FUNC PyInit_limited_api_latest(void)
15+
{
16+
import_array();
17+
import_umath();
18+
return PyModule_Create(&moduledef);
19+
}

numpy/_core/tests/examples/limited_api/meson.build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ py.extension_module(
3434
limited_api: '3.6',
3535
)
3636

37+
py.extension_module(
38+
'limited_api_latest',
39+
'limited_api_latest.c',
40+
c_args: [
41+
'-DNPY_NO_DEPRECATED_API=NPY_1_21_API_VERSION',
42+
],
43+
include_directories: [npy_include_path],
44+
limited_api: py.language_version(),
45+
)
46+
3747
py.extension_module(
3848
'limited_api2',
3949
'limited_api2.pyx',

numpy/_core/tests/test_limited_api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ def install_temp(tmpdir_factory):
4747
pytest.skip("No usable 'meson' found")
4848
if sys.platform == "win32":
4949
subprocess.check_call(["meson", "setup",
50+
"--werror",
5051
"--buildtype=release",
5152
"--vsenv", str(srcdir)],
5253
cwd=build_dir,
5354
)
5455
else:
55-
subprocess.check_call(["meson", "setup", str(srcdir)],
56+
subprocess.check_call(["meson", "setup", "--werror", str(srcdir)],
5657
cwd=build_dir
5758
)
5859
try:
59-
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)
60+
subprocess.check_call(
61+
["meson", "compile", "-vv"], cwd=build_dir)
6062
except subprocess.CalledProcessError as p:
6163
print(f"{p.stdout=}")
6264
print(f"{p.stderr=}")
@@ -84,5 +86,6 @@ def test_limited_api(install_temp):
8486
and building a cython extension with the limited API
8587
"""
8688

87-
import limited_api1
88-
import limited_api2
89+
import limited_api1 # Earliest (3.6)
90+
import limited_api_latest # Latest version (current Python)
91+
import limited_api2 # cython

0 commit comments

Comments
 (0)