On Tue, Aug 5, 2008 at 3:38 PM, Paul Pogonyshev <[EMAIL PROTECTED]> wrote:
> Py_CLEAR way: > > Py_CLEAR (self->x); > /* But __del__ can now in principle trigger access to NULL. */ > self->x = y; > Py_INCREF (self->x); The Py_DECREF inside the Py_CLEAR may call arbitrary code while self->x points to NULL. This is OK if you write your code to recognize that self->x may be NULL. Without Py_CLEAR, a Py_DECREF may call arbitrary code while self->x points to a deallocated object. This is never OK since it's impossible to detect that self->x is bogus. Generally, I end up storing all the objects to be Py_DECREF'd in temporary variables and doing the Py_DECREF's just before returning. That way, "self" is never in an inconsistent state. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com