From: Glen W. M. <Gle...@sw...> - 2006-06-16 16:24:00
|
Hello, I am writing a python extension module to create an interface to some C code, and am using numpy array as the object type for transferring data back and forth. Using either the numpy svn from yesterday, or 0.9.6 or 0.9.8, with or without optimized ATLAS installation, I get a segfault at what should be the most straightforward of all operations: PyArray_Check() on the input argument. That is, when I run: import DFALG DFALG.bsvmdf( 3 ) after compiling the below code, it always segfaults, regardless of the type of the argument given. Just as a sanity check (it's been a little while since I have written an extension module for Python) I changed the line containing PyArray_Check() to one that calls PyInt_Check(), which does perform exactly how I would expect it to. Is there something I'm missing? Thank you! Glen Mabey #include <Python.h> #include <arrayobject.h> static PyObject * DFALG_bsvmdf(PyObject *self, PyObject *args); static PyMethodDef DFALGMethods[] = { {"bsvmdf", DFALG_bsvmdf, METH_VARARGS, "This should be a docstring, really."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC initDFALG(void) { (void) Py_InitModule("DFALG", DFALGMethods); } static PyObject * DFALG_bsvmdf(PyObject *self, PyObject *args) { PyObject *inputarray; //printf( "Hello, Python!" ); //Py_INCREF(Py_None); //return Py_None; if ( !PyArg_ParseTuple( args, "O", &inputarray ) ) return NULL; if ( PyArray_Check( inputarray ) ) { //if ( PyInt_Check( inputarray ) ) { printf( "DFALG_bsvmdf() was passed a PyArray.()\n" ); } else { printf( "DFALG_bsvmdf() was NOT passed a PyArray.()\n" ); } return Py_BuildValue( "ss", "Thing 1", "Thing 2" ); } |