[Pyrex] Access to nested structures and arrays
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Mar 20 00:56:22 UTC 2007
Pierre GM wrote:
> On Monday 19 March 2007 18:55:39 Greg Ewing wrote:
>
> > Let me know if you want an example.
>
> Oh yes. I've been struggling with that.
It would go something like this (not tested):
cdef extern from "Python.h":
object PyCObject_FromVoidPtr(void *, void (*)(void *))
void *PyCObject_AsVoidPtr(object)
cdef class MyThing:
MyCData *data
def __new__(self, init_data):
self.data = <MyData *> PyCObject_AsVoidPtr(init_data)
def new_thing():
MyCData *my_data = ... # get C data from somewhere
return MyThing(PyCObject_FromVoidPtr(my_data, NULL)
--
Greg
More information about the Pyrex
mailing list