Problem with dynamically linked extensions that use Numeric
Alex
cut_me_out at hotmail.com
Sun Jul 2 08:31:15 EDT 2000
Hi. I have been writing an extension that uses the Numeric API. Up
until now, I have just been building it straight into python, and it's
working fine. However, I want to make it more widely available, so I
need to make shared objects from it. The problem with that is that it
segfaults. Here is a small piece of code that demonstrates the problem
I am having:
///////////////////////////////////////////////////////////////////////////////
#include "Python.h"
#include "arrayobject.h"
PyObject *test_array_test (PyObject *self, PyObject *args) {
PyObject *t;
int dimensions[2], i;
if (!PyArg_ParseTuple (args, "")) {
return NULL;
}
dimensions[0] = 10; dimensions[1] = 12;
for (i=0; i < 20; i++) {
printf ("testing\n");
t = PyArray_FromDims (2, dimensions, PyArray_INT);
}
if (!t) {
return NULL;
}
return t;
}
static PyMethodDef Test_ArrayMethods[] = {
{"test", test_array_test, METH_VARARGS},
{NULL, NULL}
};
void inittest_array () {
(void) Py_InitModule ("test_array", Test_ArrayMethods);
}
///////////////////////////////////////////////////////////////////////////////
I compiled this using the 'make -f Makefile.pre.in boot' method. Here
were the commands make generated:
[alex_c at puffin blast]$ make test_arraymodule.so
gcc -I/scratch2/alex/include/python2.0/Numeric -g -O2 \
-I/scratch2/alex/include/python2.0 \
-I/scratch2/alex/include/python2.0 -DHAVE_CONFIG_H \
-c ./test_arraymodule.c
gcc -shared test_arraymodule.o -o test_arraymodule.so
This code segfaults when it hits the line
't = PyArray_FromDims (2, dimensions, PyArray_INT);' But when it's
compiled directly in to python (i.e., I move the file into the Modules
directory of the python source, and add a corresponding entry in the
Setup file,) it works fine.
I'd be grateful for any ideas as to how to get this to work.
Alex.
More information about the Python-list
mailing list