[Pyrex] How to deal with a void *
Lenard Lindstrom
len-l at telus.net
Fri May 12 06:35:14 CEST 2006
If the void pointer is wrapped in an extension type then functions
dependent on it can be called from methods. This is very OO.
cdef class Resource:
cdef void *r
def __new__(self, ...):
self.r = initResource(....)
def doSomething(self, ....):
doSomething(self.r, ....)
....
It can also automatically release the resource from a __dealloc__
method.
Lenard Lindstrom
<len-l at telus.net>
On 12 May 2006 at 14:58, Greg Ewing wrote:
> Tomasz Primke wrote:
>
> > Have you tried:
> >
> > cdef void *foo
> > cdef unsigned long int *bar
> >
> > foo = initResource()
> > bar = <unsigned long int*> foo
>
> I don't think that will help the OP, because it
> sounded like he wanted to be able to pass his
> void * through Python code.
>
> The only two safe ways of doing that have already
> been suggested: wrap it in an extension type, or
> wrap it in a PyCObject.
>
More information about the Pyrex
mailing list