On Mar 26, 2009, at 6:41 PM, Lisandro Dalcin wrote:

> 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!):

Yep, that would make things clearer.

> 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...

Yes, if you're dealing with PyObject*, you'll need to worry about  
borrowed/new references yourself. <object>tmp will incref tmp.

- RObert

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

Reply via email to