
Konrad Hinsen wrote:
site = PyList_GetItem(spam_list, index);
if (! PyArray_Check(spam)) result = 0; ^^^^
Not "site"?
oops! I thought I had Pythonized everything by putting spam everywhere.
If spam is NULL, then the check will crash. If it is anything but a pointer to a Python object, there's a good chance that it might crash. PyArray_Check just tells you if a given Python object is of type "array".
Fair enough. In this case, I was getting spam from a Python list. Is it possible for it to be anything but a pointer to a Python object?
A look at the value of "spam" with a debugger should tell you what's going on.
I have not yet figured out how to use a de-bugger with a python extension. Does anyone know of any nifty tutorial for how to do this (with gdb, preferably)? note that I'm a newby to C too, so I need a really basic run through.
spam = (PyArrayObject *) PyList_GetItem(spam_list, index);
Should I be doing this, and should PyArray_Check(spam) work either way?
It works either way, but I am not sure that you are supposed to rely on that. I prefer to use a cast to array objects only *after* verifying that I have an array object, if only for clarity.
That sounds like sound advice. I do feel like I'm doing something wrong if I get a warning form the compiler however. Thanks for your help. -Chris -- Christopher Barker, Ph.D. cbarker@jps.net --- --- --- http://www.jps.net/cbarker -----@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Water Resources Engineering ------ @ ------ @ ------ @ Coastal and Fluvial Hydrodynamics ------- --------- -------- ------------------------------------------------------------------------ ------------------------------------------------------------------------