Stefan Behnel wrote:
> Robert Bradshaw wrote:
>> On Jul 6, 2009, at 11:45 AM, Dag Sverre Seljebotn wrote:
>>
>>> In updating numpy.pxd, I encountered the issue that there are
>>> exceptions
>>> from the standard refcounting rules (this also applies somewhere in
>>> CPython, e.g. PyList_SET_ITEM/GET_ITEM).
>>>
>>> Is there a way of declaring such functions in extern blocks, e.g.
>>> something like
>>>
>>> cdef extern borrowed object PyList_GET_ITEM(object, Py_ssize_t)
>>> cdef extern void PyList_SET_ITEM(object, Py_ssize_t, borrowed object)
>>>
>>> If not, should I make a ticket for it? (Just wondering what workflow I
>>> should assign to numpy.pxd; I don't have time for implementing this.)
>> The convention we've taken in Sage is that borrowed references are
>> declared as PyObject* (so to store them anywhere requires casting to
>> object, thus an incref).
>
> +1
>
>
>> When you say "borrowed" for an argument, I'm
>> assuming you mean arguments that steal references, right? I agree it
>> might be useful to have something there.
>
> ... although "borrowed" doesn't make that much sense in this context.
OK, stolen then.
>
> However, without flow analysis, it's impossible to get ref-counting right
> here:
>
> def test(x):
> a = None
> if x:
> steal_reference(a)
>
> Should "a" get decref-ed at function exit?
Well, it would be syntax candy for an extra incref. I can work around
this now by:
cdef extern void Real_PyList_SET_ITEM "PyList_SET_ITEM"(object,
Py_ssize_t, object)
cdef inline void PyList_SET_ITEM(object a, Py_ssize_t b, object c):
Py_INCREF(c)
Real_PyList_SET_ITEM(a, b, c)
For ~20 functions I am likely not going to bother; while simply declaring
cdef extern void PyList_SET_ITEM(object, Py_ssize_t, stolen object):
I could do.
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev