Lisandro wrote:
> On Wed, Jun 3, 2009 at 8:09 AM, Jon Olav Vik <[email protected]> wrote:
>>
>> Somewhere inside pysundials.cvode.NVector is an array of double
>> screaming to get out [6]. However, Dag Sverre told me that passing it
>> to Cython may require converting between ctypes and Cython pointers.
>
> if you have a 'ctypes' object , you can use ctypes.addressof() to get
> a integer (ctypes uses PyLong_FromVoidPtr()) containing the underlying
> pointer. Next, in Cython code you can use core Python C-API call
> PyLong_AsVoidPtr() to get the C-side pointer.
>
> Of course, if your odefun() is tiny, this will not alleviate the
> overhead of the Python layer.

Thanks, I wasn't aware of the addressof call. That's definitely convenient.

One thing we might want to do though is ship a ctypes.pxd for a bit faster
access directly to ctypes pointers.

Finally, while the topic is up, I personally have a wishlist item for
Cython which is automatic coercion between pointers and ctypes objects:

cdef int* i
print i # prints <ctypes.POINTER(ctypes.c_int)...> or somesuch

90% of my motivation for this behaviour is that then all cdef functions
would also be cpdef-able, and removing the need to explain that some
objects cannot be coerced to objects and back :-) Basically just more
language consistency.

Dag Sverre

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to