Embedding a Numeric array in C

Pete Shinners shredwheat at attbi.com
Tue May 21 01:06:00 EDT 2002


Chris Fonnesbeck wrote:
> I am trying to find out how to properly embed a Numeric array type in
> C.  The following code compiles, but segfaults when run:
> 
> #include <Python.h>
> #include <pythonrun.h>
> #include <Numeric/arrayobject.h>
> 
> int main() {
> 
>         PyObject *pmod;
>         char *cstr;
>         Py_Initialize();
> 
>         pmod = PyImport_ImportModule("Numeric");
>         Py_DECREF(pmod);
> 	 return 0;
> 
> }

in your "init" function, you need to make a call to "import_array()".
import_array is actually a 'magic macro' that does a sort of "runtime 
linking" in python. if you do not make this call, all the C functions from 
Numeric will only be NULL (and hence a crash)

no need for the PyImpoert_ImportModule()





More information about the Python-list mailing list