[Numpy-discussion] embedded PyArray_FromDimsAndData Segmentation Fault

Thomas Hrabe thrabe@burnham....
Wed May 14 17:42:05 CDT 2008


Hi all,

the PyArray_FromDimsAndData is still cousing me headaches. 

Is there anybody out there finding the error of the following code?

#include "Python.h"
#include <numpy/ndarrayobject.h>
int main(int argc,char** argv)
{

	int dimensions = 2;

	void* value = malloc(sizeof(double)*100);

	int* size = (int*)malloc(sizeof(int)*2);

	size[0] = 10;
	size[1] = 10;

	for(int i=0;i<100;i++)
		((double*)value)[i] = 1.0;

	for(int i=0;i<100;i++)
		printf("%e ",((double*)value)[i]);

	printf("\n%d %d\n",dimensions,size[0]);
	PyArray_FromDimsAndData(dimensions,size,NPY_DOUBLELTR,(char*)value); //TROUBLE HERE

        return 0;
}

I allway get a segmentation fault at the PyArray_FromDimsAndData call. 
I want to create copies of c arrays, copy them into a running python interpreter as nd-arrays and modify them with some python functions.

If I did this in a module, I would have to call the 
import_array();
function, I know. However, this is all outside of any module and when I add it before PyArray_FromDimsAndData I get the following compilation error:
src/test.cpp:24: error: return-statement with no value, in function returning 'int'

Does anybody have a clue?
Best,
Thomas



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080514/880fb1f5/attachment.html 


More information about the Numpy-discussion mailing list