SWIG / Numeric core dump

The following Python / SWIG / Numeric program dumps core. I use RedHat Linux 7.1 on a PC. Python 2.1, Numeric 20.1.0, SWIG 1.1 build 883, gcc 2.96. What is the problem? The output looks like:
The program files are: ---------------------------------------------- doit.py: #! /usr/bin/python import Numeric, spam spam.funct() print 'spam.funct completed' ---------------------------------------------- spam.h: #include "Python.h" #include "/usr/include/python2.1/Numeric/arrayobject.h" void funct(void); ---------------------------------------------- spam.i %module spam %{ #include "spam.h" %} %init %{ import_array(); printf("called import_array\n"); %} void funct(void); ---------------------------------------------- spammodule.c #include "spam.h" void funct(void) { PyArrayObject *pao; int dims[2]; dims[0] = 100; dims[1] = 200; printf("Calling PyArray_FromDims\n"); pao = (PyArrayObject*) PyArray_FromDims(2, dims, PyArray_UBYTE); printf("Completed PyArray_FromDims\n"); Py_DECREF(pao); } ---------------------------------------------- swigit: swig -python spam.i gcc -c -Wall spammodule.c spam_wrap.c -I/usr/include/python2.1 ld -shared spammodule.o spam_wrap.o -o spam.so

The best way of finding core dumps with a Python extension is to compile the extension source with '-g', and then follow these steps. (You may also have to compile the Numeric Extensions with '-g', to trace into them). % gdb /usr/bin/python2.1 (gdb) br _PyImport_LoadDynamicModule (gdb) cont # repeat until your extension is loaded (gdb) finish # to load your extension (gdb) br wrap_myfunction (gdb) disable 1 # don't want to break for more modules being loaded (gdb) continue Note: you can't set a breakpoint in your code until your module has been loaded. -- Joe VanAndel National Center for Atmospheric Research http://www.atd.ucar.edu/~vanandel/ Internet: vanandel@ucar.edu

The best way of finding core dumps with a Python extension is to compile the extension source with '-g', and then follow these steps. (You may also have to compile the Numeric Extensions with '-g', to trace into them). % gdb /usr/bin/python2.1 (gdb) br _PyImport_LoadDynamicModule (gdb) cont # repeat until your extension is loaded (gdb) finish # to load your extension (gdb) br wrap_myfunction (gdb) disable 1 # don't want to break for more modules being loaded (gdb) continue Note: you can't set a breakpoint in your code until your module has been loaded. -- Joe VanAndel National Center for Atmospheric Research http://www.atd.ucar.edu/~vanandel/ Internet: vanandel@ucar.edu
participants (2)
-
Edward C. Jones
-
Joe Van Andel