[C++-sig] How do I make correct wrappers to interfaces while using shared_ptrs?

Adam Preble adam.preble at gmail.com
Sun Feb 5 06:56:37 CET 2012


On Sat, Feb 4, 2012 at 8:48 PM, Jim Bosch <talljimbo at gmail.com> wrote:

> Oh, you're right.  I was confusing the manual way of doing Python-side
> polymorphism (derived-class holders) with the more automatic (and better)
> way you're doing it (with wrapper).  Your original code was fine in that
> regard.
>
> Anyhow, looking closer, here's what you need to do:
>
>  - Put your code back to what it was before I told you to change it.
>
>  - Add another line, after the class wrappers:
>
> register_ptr_to_python< boost::shared_ptr<**Communicatable> >();
>
> That explicitly registers a shared_ptr converter for Communicatable. I'm
> not sure why Boost.Python doesn't automatically do that when you register
> converters for its derived classes (those are registered by putting the
> shared_pr types in the template parameters to class_).  It might just be an
> oversight, or it might be that doing the base class registration
> automatically would cause problems in some contexts.
>
>
> The appears to do the trick.  I'm wondering--how do you figure out stuff
like that?  That isn't the kind of thing that could have just occurred to
me.

This little test program works, but so far I haven't resolved the crash in
my more complicated code that's coming a Python subclass of a C class
trying to get a callback from Python instance of a C class . . . it's rough
even explaining it.  I'll have to review my code and make sure I'm doing
that in all the right places.  Either I get it working because of these
little things here, or I'll be back with a modification of this source to
show the problem with shared_ptr conversion that I was seeing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120204/dffe2b77/attachment.html>


More information about the Cplusplus-sig mailing list