Pyrex pointer problem

Edward C. Jones edcjones at
Wed Apr 23 17:12:46 CEST 2003

I use Pyrex 0.7.2 and Python 2.2.2. For line "return" in
"wrapped.pyx", I get the error message:

     Cannot convert 'A_Struct' to Python object

How do I fix this? How can I get a list of Python and C variables (or
objects) for a program?


typedef struct {
     int iVal;
     struct A_Struct* as;
} A_Struct;


#include "astruct.h"


ctypedef int size_t

cdef extern from "stdlib.h":
     void* malloc(size_t size)
     void free(void* ptr)

cdef extern from "astruct.h":
     ctypedef struct c_A_Struct "A_Struct":
         int iVal
         c_A_Struct* as

cdef class A_Struct:
     cdef c_A_Struct* t

     def __new__(self, i):
         self.t = <c_A_Struct*> malloc(sizeof(c_A_Struct))
         if self.t == NULL:
             raise MemoryError
         self.t.iVal = i = self.t

     def __dealloc__(self):

     def __getattr__(self, name):
         if name == 'iVal':
             return self.t.iVal
         if name == 'as':
         return object.__getattribute__(self, name)

     def __setattr__(self, name, val):
         if name == 'iVal':
             self.t.iVal = val
         if name == 'as':
    = val
             object.__setattr__(self, name, val)

More information about the Python-list mailing list