[C++-sig] Re: Containers for derived classes

Brett Calcott brett.calcott at paradise.net.nz
Sat Aug 9 06:20:29 CEST 2003


> Brett, I hate to be so blunt, but unless I'm misunderstanding you,
> this explanation is almost completely wrong.

Blunt is fine. honesty won't offend.

>
> > The problem is that for python object 'identity' the PyObject must
survive
> > making it from the python interpreter to C++, and back again.
>
> True.
>
> > In this case it doesn't -- it is deleted when you set it, and a new
> > one is constructed when it returns.
>
> False; with all recent CVS versions boost::shared_ptr<T> converted from
> python actually manages the containing Python object and will convert
> back into the same object when converted to python.

Ok, I'm confused. Clearly object identity is *not* preserved - so they can't
be the same PyObject. Doesn't that require the old one to have been deleted
(well, derefed at least) and a new one created? From your other reply it
seems that this is the case - because of the ordering of the converters. I
can't see what was False about what I said here.

>
> >
> > Try this instead:
> >
> > ...
> >     // class_<A, A_ptr>("A", init< int >() )
> >     class_<A, boost::noncopyable>("A", init< int >() )
> > ...
> >
> >
> > This does work. Why? Because Boost.Python uses shared_ptr<A>
*internally* to
> > construct this object
>
> Where did you get that idea?

By incorrect reasoning :(
My apologies.










More information about the Cplusplus-sig mailing list