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.
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?
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev