Guido van Rossum wrote:
> I don't see a way that __del__ could be invoked and access the NULL
> between the Py_CLEAR() call and the Py_INCREF() call in the second
> version.
Consider this:
class Bad:
def __del__(self):
obj.some_method()
obj.set_foo(Bad())
obj.set_foo(None)
Now,
On Tue, Aug 5, 2008 at 4:30 PM, Paul Pogonyshev <[EMAIL PROTECTED]> wrote:
> > 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.
>
> Right. But woul
Paul Pogonyshev wrote:
del obj.x
obj.x = y
though I'm not sure if for Python code x.__del__ will see obj.x as
non-set attribute (I guess so, but I'm not sure).
A quick experiment suggests that it does:
Python 2.5 (r25:51908, Apr 8 2007, 22:22:18)
[GCC 3.3 20030304 (Apple Com
Paul Pogonyshev gmx.net> writes:
>
> Right. But wouldn't it be easier if there was a standard Python macro
> for this, sort of like proposed Py_ASSIGN?
I proposed something similar in http://bugs.python.org/issue3081.
___
Python-Dev mailing list
Py
Daniel Stutzbach wrote:
> 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_
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 arbitra
I don't see a way that __del__ could be invoked and access the NULL
between the Py_CLEAR() call and the Py_INCREF() call in the second
version.
On Tue, Aug 5, 2008 at 1:38 PM, Paul Pogonyshev <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Sorry if this topic was discussed before, but I couldn't find.
>
> Py
Hi,
Sorry if this topic was discussed before, but I couldn't find.
Py_CLEAR documentation explains why it is better than Py_DECREF and
NULL assignment. However, I don't understand why there is no similar
macro for the case you want to replace one object with another?
I.e. 'naive' way: