[SciPy-dev] PyArray_New problem

Travis Oliphant oliphant.travis at ieee.org
Fri Dec 2 10:16:36 CST 2005


Robert Cimrman wrote:

>Travis Oliphant wrote:
>  
>
>>Robert Cimrman wrote:
>>
>>
>>    
>>
>>>Could someone tell me what I am doing wrong? I would like to use a
>>> function like the snippet below to create an array.
>>>
>>>PyArrayObject *helper_newCArrayObject_i32( int32 len, int32 *array
>>>) { intp plen[1]; PyArrayObject *obj = 0;
>>>
>>>plen[0] = len; printf( "11111 %d\n", PyArray_INT32 ); /*   obj =
>>>(PyArrayObject *) PyArray_SimpleNew( 1, plen, PyArray_INT32 ); */
>>>
>>>obj = (PyArrayObject *) PyArray_New( &PyArray_Type, 1, plen, 
>>>PyArray_INT32, NULL, NULL, 0, CARRAY_FLAGS, NULL ); ....
>>>
>>>
>>>      
>>>
>>First of all, don't pass in CARRAY_FLAGS when the data argument to 
>>PyArray_New is NULL.  A non-zero flags entry tells the subroutine to
>> create a FORTRAN strides array if no data is passed.
>>
>>Remember:  DATA flags are only to describe already available memory.
>> If you create the memory  in PyArray_New, then the only thing to
>>decide is FORTRAN or C- contiguous.   So, in this routine, you are
>>creating a Fortran array.  Perhaps this is causing problems later.
>>    
>>
>
>I understand this - I first tried with  PyArray_SimpleNew(), then with
>PyArray_New() with zero flags and finally tried to play with the flags 
>to no avail.
>
>  
>
>>Also, you are not showing us the rest of the code.  Your traceback is
>> showing PyArray_ValidType being called which is not shown anywere...
>>    
>>
>
>Well, that is what is really strange - I have just traced the execution 
>with gdb and what is hapenning is, that, instead of PyArray_New(), 
>PyArray_ValidType() gets called, and so, obviously, it sees 
>&PyArray_Type as its 'int type', which is -1212938592 in my case -> 
>segfault. I am clueless why this happens.
>
>  
>
Have you completely re-compiled since upgrading your scipy_core 
installation.  If you haven't, you are using the wrong function-pointer 
table (the C-API is actually a function-pointer table).  If there are 
changes to the C-API and you don't recompile, this kind of thing happens.


-Travis




More information about the Scipy-dev mailing list