[Python-Dev] Add Py_REPLACE and Py_XREPLACE macros
Serhiy Storchaka
storchaka at gmail.com
Tue Feb 25 20:10:19 CET 2014
17.02.14 01:27, Nick Coghlan написав(ла):
> This change doesn't fix any of the known crashers in Lib/test/crashers,
> though - I applied the patch locally and checked.
It fixes other crasher (http://bugs.python.org/issue20440#msg209713).
> The point is that people already know what Py_CLEAR does. This operation
> is like Py_CLEAR (the old reference is only removed *after* the pointer
> has been updated), except that the value it is being replaced with can
> be something other than NULL. If the replacement value *is* NULL, then
> the new operation is *exactly* equivalent to Py_CLEAR.
>
> Operations that do related things should ideally have related names. The
> point of my deliberately erroneous expansion is that it's an error a
> reader can make while still correctly understanding the *logic* of the
> code, even though they're missing a subtlety of the mechanics.
Py_CLEAR and Py_DECREF have no related names. I think that the clarity
and briefness are important. I assume that these macros will be widely
used (they allow existing code to write shorter), perhaps even more than
Py_CLEAR. Therefore people will know what they do.
> An explicit name like Py_SET_AND_DECREF would also be reasonable. It's
> substantially less confusing than Py_REPLACE, as it is less ambiguous
> about whether or not the refcount on the new value is adjusted.
I agree if it will satisfy Martin, although this name looks ugly to me.
More information about the Python-Dev
mailing list