Skip to content

Commit

Permalink
MAINT: fix an incorrect pointer type usage in f2py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rgommers authored and charris committed Sep 6, 2022
1 parent 499ad3b commit 5286e57
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions numpy/f2py/cfuncs.py
Expand Up @@ -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;
Expand Down

0 comments on commit 5286e57

Please sign in to comment.