From ecae4573f018306fabf72cf053ff4568ffe84508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Fri, 8 Mar 2024 09:21:13 +0100 Subject: [PATCH] BLD: fix building against numpy dev --- erfa/ufunc.c.templ | 13 +++++++++---- pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/erfa/ufunc.c.templ b/erfa/ufunc.c.templ index 773b98c..ba2fc2b 100644 --- a/erfa/ufunc.c.templ +++ b/erfa/ufunc.c.templ @@ -17,6 +17,11 @@ #include "erfa.h" #include "erfaextra.h" +// Backported NumPy 2 API (can be removed if numpy 2 is required) +#if NPY_ABI_VERSION < 0x02000000 +#define PyDataType_ELSIZE(descr) ((descr)->elsize) +#endif + // On gcc<10 we can run into the following: // // error: dereferencing pointer to incomplete type 'PyTypeObject' @@ -376,7 +381,7 @@ ufunc_loop_matches(PyUFuncObject *self, */ if (types[i] == NPY_VOID && dtypes != NULL) { int op_descr_type_num = op_descr->type_num; - int dtype_elsize = dtypes[i]->elsize; + npy_intp dtype_elsize = PyDataType_ELSIZE(dtypes[i]); /* * MHvK: we do our own check on casting, since by default * all items can cast to structured dtypes (see gh-11114), @@ -391,12 +396,12 @@ ufunc_loop_matches(PyUFuncObject *self, return 0; } } - else if (dtypes[i]->elsize == 1 || dtypes[i]->elsize == 12) { + else if (dtype_elsize == 1 || dtype_elsize == 12) { /* string structured array; string argument is OK */ if (!((op_descr_type_num == NPY_STRING && - op_descr->elsize <= dtype_elsize) || + PyDataType_ELSIZE(op_descr) <= dtype_elsize) || (op_descr_type_num == NPY_UNICODE && - op_descr->elsize >> 2 <= dtype_elsize))) { + PyDataType_ELSIZE(op_descr) >> 2 <= dtype_elsize))) { return 0; } } diff --git a/pyproject.toml b/pyproject.toml index 287447c..0b46469 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,6 @@ requires = [ "setuptools", "setuptools_scm>=6.2", "jinja2>=2.10.3", - "numpy" + "numpy>=1.25", ] build-backend = 'setuptools.build_meta'