PyList_SetItem vs PyList_SETITEM

From what I can tell, the difference between PyList_SetItem and PyList_SETITEM is that PyList_SetItem will decrease the reference count of the list item that it overwrites, and PyList_SETITEM does not.

Is there a reason why I shouldn't just use PyList_SetItem all the time? Or will I have problems if I used PyList_SetItem to initialize the index position in the list?

+5
source share
1 answer

PyList_SET_ITEM- an unsafe macro that basically binds an object to an internal array of list pointers without any border checks. If something is not NULLin the iith position of the list, a reference leak will occur. PyList_SET_ITEMsteals a link to the object that you entered in the list. PyList_SetItemalso steals the link, but checks the borders and decrees for everything that may be in the ith position. The rule of thumb is to use PyList_SET_ITEMto initialize the lists you just created, and PyList_SetItemotherwise. It is also completely safe to use PyList_SetItemeverywhere; PyList_SET_ITEM- This is basically a hacking speed.

+6
source

All Articles