From 8d4c0496adac3c969cff629cea2236fc2d2392c5 Mon Sep 17 00:00:00 2001 From: Mike Boyle Date: Mon, 18 Dec 2023 23:50:45 -0500 Subject: [PATCH] Work around const qualification of UFunc inner loops --- src/numpy_quaternion.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/numpy_quaternion.c b/src/numpy_quaternion.c index e5927b4..fa94929 100644 --- a/src/numpy_quaternion.c +++ b/src/numpy_quaternion.c @@ -3,6 +3,16 @@ #define NPY_NO_DEPRECATED_API NPY_API_VERSION +// Numpy 1.19 changed UFuncGenericFunction to use const `dimensions` and `steps` pointers. +// Supposedly, this should only generate warnings, but this is now the cause of errors +// in CI, so I'm fixing it for real. The API version at which this change was made is at +// https://github.com/numpy/numpy/blob/e75214c1bc34903e6fe0f643dae8ada02529c0d5/numpy/core/meson.build#L41C3-L41C13 +#if C_API_VERSION >= 0x0000000d +#define NPY_INTP_CONST npy_intp const +#else +#define NPY_INTP_CONST npy_intp +#endif + #include #include #include @@ -1129,8 +1139,8 @@ static void register_cast_function(int sourceType, int destType, PyArray_VectorU // numpy array of quaternions. #define UNARY_GEN_UFUNC(ufunc_name, func_name, ret_type) \ static void \ - quaternion_##ufunc_name##_ufunc(char** args, npy_intp* dimensions, \ - npy_intp* steps, void* NPY_UNUSED(data)) { \ + quaternion_##ufunc_name##_ufunc(char** args, NPY_INTP_CONST* dimensions, \ + NPY_INTP_CONST* steps, void* NPY_UNUSED(data)) { \ /* fprintf (stderr, "file %s, line %d, quaternion_%s_ufunc.\n", __FILE__, __LINE__, #ufunc_name); */ \ char *ip1 = args[0], *op1 = args[1]; \ npy_intp is1 = steps[0], os1 = steps[1]; \ @@ -1170,7 +1180,7 @@ UNARY_UFUNC(parity_conjugate, quaternion) UNARY_UFUNC(parity_symmetric_part, quaternion) UNARY_UFUNC(parity_antisymmetric_part, quaternion) static void -quaternion_positive_ufunc(char** args, npy_intp* dimensions, npy_intp* steps, void* NPY_UNUSED(data)) { +quaternion_positive_ufunc(char** args, NPY_INTP_CONST* dimensions, NPY_INTP_CONST* steps, void* NPY_UNUSED(data)) { char *ip1 = args[0], *op1 = args[1]; npy_intp is1 = steps[0], os1 = steps[1]; npy_intp n = dimensions[0]; @@ -1186,8 +1196,8 @@ quaternion_positive_ufunc(char** args, npy_intp* dimensions, npy_intp* steps, vo // numpy array of quaternions. #define BINARY_GEN_UFUNC(ufunc_name, func_name, arg_type1, arg_type2, ret_type) \ static void \ - quaternion_##ufunc_name##_ufunc(char** args, npy_intp* dimensions, \ - npy_intp* steps, void* NPY_UNUSED(data)) { \ + quaternion_##ufunc_name##_ufunc(char** args, NPY_INTP_CONST* dimensions, \ + NPY_INTP_CONST* steps, void* NPY_UNUSED(data)) { \ /* fprintf (stderr, "file %s, line %d, quaternion_%s_ufunc.\n", __FILE__, __LINE__, #ufunc_name); */ \ char *ip1 = args[0], *ip2 = args[1], *op1 = args[2]; \ npy_intp is1 = steps[0], is2 = steps[1], os1 = steps[2]; \