From 5286e579f32115f778e15738932dc56369b7ff85 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Wed, 31 Aug 2022 21:06:49 +0300 Subject: [PATCH] MAINT: fix an incorrect pointer type usage in f2py This was giving many warnings like this one in the SciPy build: ``` scipy/special/_specfunmodule.c: In function 'complex_double_from_pyobj': scipy/special/_specfunmodule.c:198:47: warning: passing argument 1 of 'PyArray_DATA' from incompatible pointer type [-Wincompatible-pointer-types] 198 | (*v).r = ((npy_cdouble *)PyArray_DATA(arr))->real; | ^~~ | | | PyObject * {aka struct _object *} In file included from /home/rgommers/code/numpy/numpy/core/include/numpy/ndarrayobject.h:12, from /home/rgommers/code/numpy/numpy/core/include/numpy/arrayobject.h:5, from /home/rgommers/code/numpy/numpy/f2py/src/fortranobject.h:16, from scipy/special/_specfunmodule.c:22: /home/rgommers/code/numpy/numpy/core/include/numpy/ndarraytypes.h:1524:29: note: expected 'PyArrayObject *' {aka 'struct tagPyArrayObject *'} but argument is of type 'PyObject *' {aka 'struct _object *'} 1524 | PyArray_DATA(PyArrayObject *arr) | ~~~~~~~~~~~~~~~^~~ ``` Fixing pointer mismatches is important for Pyodide/Emscripten. --- numpy/f2py/cfuncs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index f69933543918..408587d05364 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -1116,12 +1116,12 @@ return 1; } if (PyArray_CheckScalar(obj)) { /* 0-dim array or still array scalar */ - PyObject *arr; + PyArrayObject *arr; if (PyArray_Check(obj)) { - arr = PyArray_Cast((PyArrayObject *)obj, NPY_CDOUBLE); + arr = (PyArrayObject *)PyArray_Cast((PyArrayObject *)obj, NPY_CDOUBLE); } else { - arr = PyArray_FromScalar(obj, PyArray_DescrFromType(NPY_CDOUBLE)); + arr = (PyArrayObject *)PyArray_FromScalar(obj, PyArray_DescrFromType(NPY_CDOUBLE)); } if (arr == NULL) { return 0;