[Pyrex] Pyrex self-referential pointer problem
Edward C. Jones
edcjones at erols.com
Thu Apr 24 04:29:51 CEST 2003
I use Pyrex 0.7.2 and Python 2.2.2. For line "return self.t.as" 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?
For this program "pyrexc wrapped.pyx" works but "wrapped.c" won't
compile. The gcc error messages are hard to interpret in terms of
"wrapper.pyx". Are there any plans to address this situation?
The code is slightly different from what I posted to comp.lang.python.
--------------
astruct.h:
typedef struct {
int iVal;
struct A_Struct* asp;
} A_Struct;
--------------
astruct.c
#include "astruct.h"
--------------
wrapped.pyx:
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* c_asp "asp"
cdef class A_Struct:
cdef c_A_Struct* t
def __new__(self, i):
self.t = <c_A_Struct*> malloc(sizeof(c_A_Struct))
self.t.iVal = i
self.t.c_asp = self.t
def __dealloc__(self):
free(self.t)
def __getattr__(self, name):
if name == 'iVal':
return self.t.iVal
if name == 'iVal2':
return self.t.c_asp.iVal
return object.__getattribute__(self, name)
def __setattr__(self, name, val):
if name == 'iVal':
self.t.iVal = val
else:
object.__setattr__(self, name, val)
More information about the Pyrex
mailing list