[C++-sig] Stuck on accessing numpy.ndarray in c extension

Qinfeng(Javen) Shi shiqinfeng at gmail.com
Mon Sep 25 16:39:52 CEST 2006


No, I did not use raw_function for the export.I tried hello.testArray((c,)),
it crashed.

Then I used PyArray_Check(args) to check the input type, it crashed even
when I passed a numpy.ndarray to it.
void testArray(PyObject * args)
{
    if(!(PyArray_Check(args)))
    {
        printf("args is not list type!\n");
        return;
    }
}

>>> a = numpy.arange(25).reshape((5,5));
>>> rarray2 = hello.testArray(a,)
Segmentation fault

>>> a = numpy.arange(25).reshape((5,5));
>>> rarray2 = hello.testArray(a)
Segmentation fault

A *segmentation* *fault* occurs when a program attempts to access a memory
location that it is not allowed to access, or attempts to access a memory
location in a way that is not allowed.
It seems my PyObject * args can not neither be acessed by PyArray_Check()
nor by PyArg_ParseTuple().

I don't get it.
-- 
Qinfeng(Javen) Shi

Research School of Information Sciences and Engineering
Australian National University
Locked Bag 8001
Canberra ACT 2601
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060926/195ab878/attachment.htm>


More information about the Cplusplus-sig mailing list