[Pyrex] Casting Python sequence to pointer and vice versa

Lenard Lindstrom len-l at telus.net
Sun Mar 4 01:42:38 UTC 2007


Christian Heimes wrote:
> As a Pyrex newbie I missed some good examples in the docs or example
> directory. I tried different ways like
>
> cdef unsigned long *v
> v = pythonlist
>
> but it didn't work. I expected Pyrex to do all the dirty walk like
> malloc() for me. It looks like I coded too much Python in the path and
> forgot all about manual memory management and pointers on pointers on
> structs ... :)
>   

Consider Python's array type. Within Pyrex create a array from the list, 
then use the PyObject_AsWriteBuffer Python C api function to get at the 
array's contents. The array will do memory management and list conversions.

-- 
Lenard Lindstrom
<len-l at telus.net>




More information about the Pyrex mailing list