From numpy matrix to C array. Segmentation fault (memory corruption) on 64bit architecture -
i'm trying build python c extension in order pass numpy matrix c array. following suggestions reported here: http://wiki.scipy.org/cookbook/c_extensions/numpy_arrays but when python tries run c line: v=(float **)malloc((size_t) (n*sizeof(float))); of follow portion of code: float **_ptrvector(long n) { float **v; v=(float **)malloc((size_t) (n*sizeof(float))); if (!v) { printf("in **ptrvector. allocation of memory array failed."); exit(0); } return v; } float **pymatrix_to_carray(pyarrayobject *arrayin) { float **c, *a; int i,n,m; n = pyarray_dim(arrayin, 0); m = pyarray_dim(arrayin, 1); c=_ptrvector(n); = (float*) pyarray_data(arrayin); ( i=0; i<n; i++) { c[i]=a+i*m; } return c; } i segmentation fault on linux 64 bit machine. problem code works on 32 bit machines (both windows , linux). sizeof(size_t) returns correctly 4 on 32bit machines , 8 on 64bit machines. i'm us