[pypy-dev] PyArray_Type cpyext bug
Antonio Cuni
anto.cuni at gmail.com
Fri Nov 22 19:11:04 CET 2013
Hi,
I committed a cpyext+numpy failing test in a3c3b75a7f2b.
In short, the following fails:
if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &obj))
return NULL;
The problem is that PyArray_Type is currently defined in ndarrayobject.c but
never initialized:
PyTypeObject PyArray_Type;
not a suprise that we get a segfault when we try to use it.
However, I'm not sure about what is the best way to fix it, so I ask the
cpyext wizards :)
I think that at the end what we want is an object for which &PyArray_Type is
equal to the PyObject* that we get when we pass _numpypy.multiarray.ndarray to C.
One possibility is to run the following code in some initialization function:
static PyObject* _PyArray_Type;
#define PyArray_Type (*_PyArray_Type)
PyObject* np = PyImport_ImportModule("numpy");
if (!np)
return;
_PyArray_Type = PyObject_GetAttrString(np, "ndarray");
if (!My_PyArray_Type)
return;
I'm sure there is a better way to do this. However, I tried to play with the
cpyext source for a while and didn't manage to find it. Any suggestion?
ciao,
Anto
More information about the pypy-dev
mailing list