[C++-sig] Re: call_method

Brett Calcott brett.calcott at paradise.net.nz
Sun Nov 17 06:23:16 CET 2002


> >
> > *Just* like this? A couple of posts back you said:
> >
> >>> 2. Prepare a special "self_base" class that can be used as a base of
> >>>    "callback" classes like BaseWrap from the examples. This base would
> >>>    hold the "self" pointer.
> >
> > Where is this base class in here?
>
> Yeah, yeah, sure. You'd do that if you want to make sure the identity
> of the Python instance is preserved when you hold it by
> shared_ptr<agent> and then pass it back to Python. I wasn't sure you
> needed that functionality for your application... but maybe you do.
>

I don't know I need it *right now*, but I suspect it will come back and bite
me if there is not python object identity.

>
> > But this suggests that agent is derived directly from self_base:
> >
> >>    Most-importantly, when references and (smart) pointers to
> >>    polymorphic classes are converted to python, we will attempt to
> >>    downcast to "self_base", and if successful, we'll return the
> >>    contained self pointer instead of a new object
>
>
> I did say "downcast" didn't I? Inheritance DAGs are usually written
> with derived classes at the bottom.
>

Not the first time I've got this round the wrong :(

>
> > My blind spot was not properly understanding shared_ptr. Wow, it is
> > *extremely* cool.
>
> Is it not? IS IT NOT?!
>
> I am more and more impressed with Peter's design the more I look at
> it.

Likewise. My handrolled smart_ptr's of yesteryear look pretty naive now...

>
> > Ok, now I am getting it. The inheritance is still not clear to me.
> >
> > From a previous post:
> >>    Most-importantly, when references and (smart) pointers to
> >>    polymorphic classes are converted to python, we will attempt to
> >>    downcast to "self_base", and if successful, we'll return the
> >>    contained self pointer instead of a new object
> >
> > This suggests that agent is derived from self_base, not
multiply-inherited
> > in agent_callback.
>
> I don't know what suggests that.

More downcast blundering on my part here.

>
> > The agent might have been created from the c++ side - so the
> > self_pointer might be null. How do we deal with this case?
>
> If it was created from the C++ side, the downcast to self_base will
> fail because there is no associated Python object. In that case you
> just create a new Python object around the C++ object.
>

So, in python, getting the same C++ agent twice won't give us the same
python object? I can live with that...


> We can also think about doing some deleter introspection to get even
> more power out of this. See
> http://aspn.activestate.com/ASPN/Mail/Message/boost/1437090. We can do
> this without any changes to the shared_ptr library, but it requires
> some hacks, and I'd rather convince Peter to make it part of the
> public interface.
>

This is getting better and better...

Cheers,
Brett





More information about the Cplusplus-sig mailing list