[Python-Dev] Poll: Py_REPLACE/Py_ASSIGN/etc
Kristján Valur Jónsson
kristjan at ccpgames.com
Fri Feb 28 14:58:29 CET 2014
Also, for the equivalence to hold there is no separate Py_XSETREF, the X behaviour is implied, which I favour. Enough of this X-proliferation already!
But also see the discussion on inlines. It would be great to make this an inline rather than a macro.
From: Python-Dev [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Nick Coghlan
Sent: 28. febrúar 2014 12:27
To: Larry Hastings
Cc: python-dev at python.org
Subject: Re: [Python-Dev] Poll: Py_REPLACE/Py_ASSIGN/etc
For additional context, the idea itself is necessary for the same reason Py_CLEAR was added: to help ensure that an object's state is never pointing at another object that is in the process of being deleted. The difference is that Py_CLEAR only allows setting the pointer to NULL, while the point of the new macro is to set it to an arbitrary existing point. There is no implicit incref as that isn't needed for correctness (you can do the incref before the pointer replacement, and often the reference count will already be correct without an explicit incref anyway).
With the new macro in place, the existing Py_CLEAR(x) macro would be equivalent to Py_SETREF(x, NULL).
Originally I was also concerned about the "how will people know there's no implicit incref?", but I've since become satisfied with the fact that the precedent set by the reference stealing SET_ITEM macros is strong enough to justify the shorter name.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev