Skip to content

Commit

Permalink
Merge pull request #26995 from charris/backport-26985
Browse files Browse the repository at this point in the history
BUG: Add object cast to avoid warning with limited API
  • Loading branch information
charris authored Jul 20, 2024
2 parents 9be6ad6 + 764b667 commit 4d10ffc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion numpy/_core/include/numpy/dtype_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ typedef PyArray_DTypeMeta *(PyArrayDTypeMeta_CommonDType)(

static inline PyArray_DTypeMeta *
NPY_DT_NewRef(PyArray_DTypeMeta *o) {
Py_INCREF(o);
Py_INCREF((PyObject *)o);
return o;
}

Expand Down
19 changes: 19 additions & 0 deletions numpy/_core/tests/examples/limited_api/limited_api_latest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if Py_LIMITED_API != PY_VERSION_HEX & 0xffff0000
# error "Py_LIMITED_API not defined to Python major+minor version"
#endif

#include <Python.h>
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>

static PyModuleDef moduledef = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "limited_api_latest"
};

PyMODINIT_FUNC PyInit_limited_api_latest(void)
{
import_array();
import_umath();
return PyModule_Create(&moduledef);
}
10 changes: 10 additions & 0 deletions numpy/_core/tests/examples/limited_api/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ py.extension_module(
limited_api: '3.6',
)

py.extension_module(
'limited_api_latest',
'limited_api_latest.c',
c_args: [
'-DNPY_NO_DEPRECATED_API=NPY_1_21_API_VERSION',
],
include_directories: [npy_include_path],
limited_api: py.language_version(),
)

py.extension_module(
'limited_api2',
'limited_api2.pyx',
Expand Down
11 changes: 7 additions & 4 deletions numpy/_core/tests/test_limited_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ def install_temp(tmpdir_factory):
pytest.skip("No usable 'meson' found")
if sys.platform == "win32":
subprocess.check_call(["meson", "setup",
"--werror",
"--buildtype=release",
"--vsenv", str(srcdir)],
cwd=build_dir,
)
else:
subprocess.check_call(["meson", "setup", str(srcdir)],
subprocess.check_call(["meson", "setup", "--werror", str(srcdir)],
cwd=build_dir
)
try:
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)
subprocess.check_call(
["meson", "compile", "-vv"], cwd=build_dir)
except subprocess.CalledProcessError as p:
print(f"{p.stdout=}")
print(f"{p.stderr=}")
Expand All @@ -73,5 +75,6 @@ def test_limited_api(install_temp):
and building a cython extension with the limited API
"""

import limited_api1
import limited_api2
import limited_api1 # Earliest (3.6)
import limited_api_latest # Latest version (current Python)
import limited_api2 # cython

0 comments on commit 4d10ffc

Please sign in to comment.