From: Russell E O. <ow...@as...> - 2004-05-12 23:59:00
|
I modified an existing numeric c extension today, adding a function that returns a new array. This is the first time I've used NA_NewArray. The code seems to run fine, but I get a disturbing compiler warning: [rowen:Shared Files/Guider/PyGuide] rowen% python setup.py build ... src/radProfModule.c: In function `Py_radSqByRadInd': src/radProfModule.c:378: warning: return from incompatible pointer type The associated code can be summarized as follows (and it is simple enough that I've also appended a copy). The error is thrown on the last line: static PyObject *Py_radSqByRadInd(PyObject *self, PyObject *args) { long nElt; Long *radSqByRadInd; if (!PyArg_ParseTuple(args, "l", &nElt)) return NULL; ... return NA_NewArray((void *)radSqByRadInd, tLong, 1, nElt); } So...am I actually doing something wrong, or is this warning normal? -- Russell P.S. the full code: static PyObject *Py_radSqByRadInd(PyObject *self, PyObject *args) { long nElt; Long radInd; char ModName[] = "radSqByRadInd"; Long *radSqByRadInd; if (!PyArg_ParseTuple(args, "l", &nElt)) return NULL; if (nElt < 0) { PyErr_Format(PyExc_ValueError, "%s: nPts < 0", ModName); return NULL; } // allocate max(3, nElt) elements (simplifies the computation // and avoids calling calloc on 0 elements) radSqByRadInd = calloc(MAX(nElt, 3), sizeof *radSqByRadInd); if (radSqByRadInd == NULL) { PyErr_Format(PyExc_MemoryError, "%s: insufficient memory", ModName); return NULL; } for (radInd=0; radInd<3; radInd++) { radSqByRadInd[radInd] = radInd; } for (radInd=3; radInd<nElt; radInd++) { radSqByRadInd[radInd] = (radInd - 1) * (radInd - 1); } return NA_NewArray((void *)radSqByRadInd, tLong, 1, nElt); } |