On Jul 7, 2009, at 4:32 AM, Stefan Behnel wrote:
> Dag Sverre Seljebotn wrote:
>> 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'm fine with that, as long as we only allow it inside of argument
> lists
> (preferrably only "extern" argument lists).
Of course, there may already be code out there that counts on the
true PyList_SET_ITEM semantics.
Another option:
cdef extern from *:
ctypedef void stolen_object "PyObject*"
cdef inline stolen_object steal(object):
Py_INCREF(o)
return <stolen_object>o
cdef extern void PyList_SET_ITEM(object, Py_ssize_t, stolen_object)
One would then call it as
PyList_SET_ITEM(L, 0, steal(item))
(Of course, PyList_SET_ITEM is worse than this, as one needs to
manually (x)decref the original spot in the list as well... This
makes me lean towards not providing it as a friendly function taking
ordinary objects).
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev