LINUX.ORG.RU

«Ошибка сегментирования» при возвращении PyArrayObject


0

0

Доброго дня уважаемые

Разбираясь с написанием разрешений для NumPy наткнулся на следующую проблему При возвращении обращении PyArrayObject при завершении программы получаю «Ошибку сегментирования»

код выглядит следующим образом

#include <python2.5/Python.h>
//#include "Python.h"
#include <numpy/arrayobject.h>
//#include "arrayobject.h"
#include "test.h"
#include <math.h>


static PyMethodDef _C_testMethods[] = {
	{"testf", testf, METH_VARARGS},
	{NULL, NULL}     /* Sentinel - marks the end of this structure */
};


void init_C_test()  {
    (void) Py_InitModule("_C_test", _C_testMethods);
	import_array();  // Must be present for NumPy.  Called first after above line.
}


static PyArrayObject *testf(PyObject *self, PyObject *args)
{
  PyArrayObject *a;
  int i,j, n, m, ndem;

  if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &a))
    return NULL;
 
  printf("nd=%d\n", ndem = a->nd);

  printf("ndemension=%dx%d\n",
	 n=a->dimensions[0],
	 m=a->dimensions[1]);

  for ( i=0; i<m; i++)  {
    for ( j=0; j<n; j++)  {
      printf("a->data[%d,%d]=%d\t",i,j,a->data[i*m+j]);
    }
    printf("\n");
  }
  a->data[0]=20;

    return a;

  //  return Py_None;

}
тестовая программа на python выглядит так
import _C_test
import numpy

b = numpy.array([[5, 6],[7, 8]], dtype=numpy.int8)
print b
print _C_test.testf(b)
print 'end'
а на выходя получаем вот что
[[5 6]
 [7 8]]
nd=2
ndemension=2x2
a->data[0,0]=5  a->data[0,1]=6  
a->data[1,0]=7  a->data[1,1]=8  
[[20  6]
 [ 7  8]]
end
Ошибка сегментирования

Подскажите в чем я неправ

Заранее благодарю

valgrind gdb в руки

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.