[Pyrex] Wrapping a (void *) cookie
Joseph Koshy
jkoshy at FreeBSD.ORG
Sun Apr 27 20:21:15 CEST 2003
Hi list,
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)
---
Defining the class as follows seems to result in the right C
output.
---"cookie.pyx"---
cdef class Cookie:
cdef cookie c
results in:
---"cookie.c"---
struct __pyx_obj_Cookie {
PyObject_HEAD
void (*c);
};
---
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'm trying to wrap a C library that uses a number of such 'handles'.
What is the correct pyrex idiom for this task?
Regards,
Koshy
<jkoshy at freebsd.org>
More information about the Pyrex
mailing list