[Pyrex] Structures containing pointers to Python objects

Konrad Hinsen hinsen at cnrs-orleans.fr
Sun Feb 1 13:47:01 CET 2004


Suppose I use the NumPy interface code from the Pyrex FAQ:

cdef extern from "Numeric/arrayobject.h":

     struct PyArray_Descr:
         int type_num, elsize
         char type

     ctypedef class Numeric.ArrayType [object PyArrayObject]:
         cdef char *data
         cdef int nd
         cdef int *dimensions, *strides
         cdef object base
         cdef PyArray_Descr *descr
         cdef int flags

How do I then write a declaration for a struct that contains a pointer 
to a NumPy array? Pyrex won't accept "ArrayType" or "ArrayType *" 
inside a struct declaration, nor "PyArrayObject *". The only solution I 
found was to add

     struct PyArrayObject:
         char *data
         int nd
         int *dimensions, *strides
         PyObject *base
         PyArray_Descr *descr
         int flags

but that means duplicating the information about the layout of the 
array object.

Konrad.





More information about the Pyrex mailing list