[Python-Dev] Py_SETREF vs. Py_XSETREF
ncoghlan at gmail.com
Mon Apr 4 05:09:56 EDT 2016
On 3 April 2016 at 17:32, Serhiy Storchaka <storchaka at gmail.com> wrote:
> Originally I proposed a pair of macros for safe reference replacing to
> reflects the duality of Py_DECREF/Py_XDECREF. ,  The one should use
> Py_DECREF and the other should use Py_XDECREF.
> But then I got a number of voices for the single name , and no one voice
> (except mine) for the pair of names. Thus in final patches the single name
> Py_SETREF that uses Py_XDECREF is used. Due to adding some overhead in
> comparison with using Py_DECREF, this macros is not used in critical
> performance code such as PyDict_SetItem().
I was one of those arguing for the single macro, and I think Alexander
raises a good point in http://bugs.python.org/issue26200#msg262204
that I don't recall seeing in the original discussion: the "X" in the
macro serves as a good shorthand for indicating that the code in
question isn't closely tracking whether or not manipulated reference
might be NULL, and hence may be a good candidate for additional
micro-optimisations that keep better track of whether or not the
pointer is NULL.
> Should we rename Py_SETREF to Py_XSETREF and introduce new Py_SETREF that
> uses Py_DECREF?
With the single-macro design put into effect and concrete problems
arising from that, I'm now more persuaded by the consistency argument
than I was originally, so +1 from me for reverting to your original
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev