On Mon, May 11, 2009 at 11:13 PM, Mohamed Lrhazi <[email protected]> wrote: > It seems I can make it work passing the address as > <size_t>&pointer[0], then recovering t as: > > cdef void *new_pointer = <void*><size_t>recovered_value > > Is this correct? or is it just luck that my program is not crashing yet :) >
It is correct as long as you pass back the "correct" integer value... If you ever make a mistake, you will likely have a segfault... Depending on your original C API, you could consider designing an more object oriented, pythonic API where your pointers are (cdef) attributes of a (cdef) class, and their methods provide access to the many function calls of the lib you are wrapping... > Thanks, > Mohamed. > > On Mon, May 11, 2009 at 9:51 PM, Mohamed Lrhazi <[email protected]> wrote: >> Hello, >> >> Is it possible in Cython to pass a void pointer to a python function, >> then have the latter send it back as a parameter to a function >> defined in Cython, then be able to reuse it? >> >> Basically, I am using a C lib that sends back these pointers, pointing >> to structures whose definitions in the header file are >> undefined/incomplete. I would like to send them as is to Python, but >> then be able to recover them back and resend them to lib. >> >> I can keep them in Cython as global variables, but was wondering if I >> could transparently pass them back and forth instead. >> >> I thought maybe I could pass the actual address, as in: <size_t>&pointer[0] >> >> but could not figure out how to make a new pointer in Cython assigning >> the recovered address to it. >> >> Thanks a lot, >> Mohamed. >> > > > > -- > " Logic merely sanctions the conquests of the intuition." > Jacques Hadamard > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
