Pyrex pointer problem
Edward C. Jones
edcjones at erols.com
Wed Apr 23 11:12:46 EDT 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?
--------------
astruct.h:
typedef struct {
int iVal;
struct A_Struct* as;
} 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* 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.as = self.t
def __dealloc__(self):
free(self.t)
def __getattr__(self, name):
if name == 'iVal':
return self.t.iVal
if name == 'as':
return self.t.as
return object.__getattribute__(self, name)
def __setattr__(self, name, val):
if name == 'iVal':
self.t.iVal = val
if name == 'as':
self.t.as = val
else:
object.__setattr__(self, name, val)
More information about the Python-list
mailing list