[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

Mark Shannon report at bugs.python.org
Mon Nov 9 09:56:57 EST 2020


Mark Shannon <mark at hotpy.org> added the comment:

I'm not convinced that this is worth the effort.

The old functions aren't going away, so these additional functions provide no real safety.
You can't stop C programmers trading away correctness for some perceived performance benefit :(

If we were designing the API from scratch, then this would be a better set of functions. But because the old functions remain, it just means we are making the API larger.


Please don't add macros, use inline functions.

There seems to be some confusion about borrowed references and stolen references in https://pythoncapi.readthedocs.io/bad_api.html#borrowed-references
"Stealing" a reference is perfectly safe. Returning a "borrowed" reference is not.

So, don't bother with `PyTuple_SetItemRef()`, as `PyTupleSetItem()` is safe.

----------
nosy: +Mark.Shannon

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42294>
_______________________________________


More information about the Python-bugs-list mailing list