On Jul 8, 2009, at 1:05 AM, Stefan Behnel wrote:

>
> Robert Bradshaw wrote:
>> Of course, there may already be code out there that counts on the
>> true PyList_SET_ITEM semantics.
>
> Certainly.
>
>
>> 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).
>
> That's because it's a macro. It's a different situation for  
> functions -
> although I can't currently find any in the C-API that really steal
> references. If users actually have to special case stolen references
> anyway, maybe this whole "stolen" business is really a non-problem...


Yep. The last thing I want is to make it easy to almost, but not  
quite, get it right. Raw PyObject* arguments make it clear that you  
have to at least think about it.

- Robert


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

Reply via email to