[C++-sig] Re: Custom WeakPtrs and "None"
Stefan Haller
haller at ableton.com
Thu Nov 18 14:41:07 CET 2004
David Abrahams <dave at boost-consulting.com> wrote:
> haller at ableton.com (Stefan Haller) writes:
>
> > The only problem is that when the object goes away, the "weak pointer"
> > on the Python side isn't set to "None". Of course, the wrapped C++ weak
> > pointer is set to NULL, but the python variable isn't aware of that
> > unless you try to access properties or call methods on it, in which case
> > it throws an exception. It would be very nice if a comparison with None
> > would return true for a weak pointer that has been set to NULL.
>
> Nothing will do that; how would you know all the places the Python
> object is bound to an attribute name or local variable?
>
> It's in the nature of Python. It has "name bindings," not "variable
> values."
Yes, I don't want the Python variable itself to be set to None
literally, I know there's no way to do that. I just want it to *look* a
bit more like None if the WeakPtr is NULL. For example, I was hoping
that it is possible to play tricks with overloading __cmp__ (or some
such) to make the expression (weakptr == None) evaluate to True if
weakptr is not None, but its pointee is NULL.
A similar problem is comparison of two weak ptrs; they compare
different, even if they point to the same underlying object. It would
be nice to compare pointees, not pointers here.
--
Stefan Haller
Ableton
http://www.ableton.com/
More information about the Cplusplus-sig
mailing list