On Thu, Mar 26, 2009 at 9:44 PM, Robert Bradshaw <[email protected]> wrote: > On Mar 26, 2009, at 4:40 PM, Hoyt Koepke wrote: > >> Hello, >> >> What would be the best way to call a python C-API function that takes >> PyObject** arguments from my cython code? >> >> I've thought about doing a hack with C macros that take the address of >> a PyObject* and call the C-API function and import them into cython as >> functions, but I'd think there's a better way. > > You can do <PyObject*>a, so do &(<PyObject*>a) to get a PyObject** >
Mmm, I believe a temporary var would be safer (think about refnanny!): cdef PyObject *tmp = NULL call_c_func(&tmp); a = <object> tmp; but take into account that now 'a' is a new ref (Am I right?), so you may need to Py_DECREF(tmp) if the returned 'tmp' is not a borrowed ref... -- 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
