+1
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.
K

From: Python-Dev [mailto:python-dev-bounces+kristjan=ccpgames....@python.org] 
On Behalf Of Nick Coghlan
Sent: 28. febrúar 2014 12:27
To: Larry Hastings
Cc: python-dev@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.

Cheers,
Nick.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to