[Pyrex] Wrapping a (void *) cookie
Greg Ewing
greg at cosc.canterbury.ac.nz
Tue Apr 29 07:32:15 CEST 2003
jkoshy at FreeBSD.ORG (Joseph Koshy) writes:
> I'd like to write a class in Pyrex that wraps a C 'handle' or 'cookie'.
>
> For example:
>
> ---"cookie.pyx"---
> cdef extern from *:
> ctypedef void * cookie
> cookie cookie_factory()
> void cookie_eater(cookie c)
> ---
>
> However, the following is rejected:
>
> ---"cookie.c"--
> cdef class Cookie:
> cdef cookie c
> def __new__(self, cookie c):
> self.c = c
Presumably, cookies are opaque objects that can only be
created by calling cookie_factory(), right? In that case,
instead of trying to pass a cookie into the constructor,
have the constructor call cookie_factory:
cdef class Cookie:
cdef cookie c
def __new__(self):
self.c = cookie_factory()
def eat(Cookie c not None):
cookie_eater(c.c)
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg at cosc.canterbury.ac.nz +--------------------------------------+
More information about the Pyrex
mailing list