On 4/23/06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
For pointer that live on the heap, Py_[X]DECREF is usually
done because either
a) the memory block containing the pointer is about to be
   released (e.g. when a tuple is deallocated), or
b) the pointer is about to be changed to point to something
   else (e.g. a setitem operation)

Eh, hang on. The reason to use Py_CLEAR() isn't that the pointer may be used after the Py_DECREF(), but that it may be used *as a result of DECREF'ing*. DECREFs can cause cleanup, which can execute arbitrary Python or C code through finalizers or weakref callbacks. So whatever you're doing after the Py_DECREF/Py_CLEAR call is immaterial to the decision to use either. You should use Py_CLEAR when the pointer you are DECREF'ing *might* go away, and is accessible from outside the function ( i.e. it isn't only reachable through automatic variables.)

However, I agree that it should be a conscious decision, and not an automatism.

--
Thomas Wouters < [EMAIL PROTECTED]>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to