[Pyrex] Wrapping a (void *) cookie

Matthias Baas baas at ira.uka.de
Sun Apr 27 20:45:50 CEST 2003


At 11:21 27.04.2003 -0700, Joseph Koshy you wrote:
>However, the following is rejected:
>
>     ---"cookie.c"--
>     cdef class Cookie:
>       cdef cookie c
>       def __new__(self, cookie c):
>         self.c = c
>
>     ---Pyrex output---
>     cookie.pyx:8:20: Can.pyx:8:20: Cannot convert Python object argument to \
>         type 'void (*)'

I suppose line 8 was this one:

     def __new__(self, cookie c):

When you instantiate the class you're going to pass a Python object as 
argument c. And you are instructing Pyrex to convert that object to "void*" 
which isn't possible since there is no pointer type in Python. Instead you 
can use Python integers to store the pointers:

     def __new__(self, long c):
         self.c = <cookie*>c

- Matthias -





More information about the Pyrex mailing list