Skip to content

Commit 4d10ffc

Browse files
authored
Merge pull request #26995 from charris/backport-26985
BUG: Add object cast to avoid warning with limited API
2 parents 9be6ad6 + 764b667 commit 4d10ffc

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
@@ -40,16 +40,18 @@ def install_temp(tmpdir_factory):
4040
pytest.skip("No usable 'meson' found")
4141
if sys.platform == "win32":
4242
subprocess.check_call(["meson", "setup",
43+
"--werror",
4344
"--buildtype=release",
4445
"--vsenv", str(srcdir)],
4546
cwd=build_dir,
4647
)
4748
else:
48-
subprocess.check_call(["meson", "setup", str(srcdir)],
49+
subprocess.check_call(["meson", "setup", "--werror", str(srcdir)],
4950
cwd=build_dir
5051
)
5152
try:
52-
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)
53+
subprocess.check_call(
54+
["meson", "compile", "-vv"], cwd=build_dir)
5355
except subprocess.CalledProcessError as p:
5456
print(f"{p.stdout=}")
5557
print(f"{p.stderr=}")
@@ -73,5 +75,6 @@ def test_limited_api(install_temp):
7375
and building a cython extension with the limited API
7476
"""
7577

76-
import limited_api1
77-
import limited_api2
78+
import limited_api1 # Earliest (3.6)
79+
import limited_api_latest # Latest version (current Python)
80+
import limited_api2 # cython

0 commit comments

Comments
 (0)