[Numpy-discussion] SWIG / Numeric core dump
Edward C. Jones
edcjones at erols.com
Fri Aug 10 17:16:04 EDT 2001
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:
> doit.py
called import_array
Calling PyArray_FromDims
Segmentation fault (core dumped)
>
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
More information about the NumPy-Discussion
mailing list