<p><br>
On Feb 5, 2012 10:15 AM, &quot;Jim Bosch&quot; &lt;<a href="mailto:talljimbo@gmail.com">talljimbo@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; On 02/05/2012 12:56 AM, Adam Preble wrote:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Feb 4, 2012 at 8:48 PM, Jim Bosch &lt;<a href="mailto:talljimbo@gmail.com">talljimbo@gmail.com</a><br>
&gt;&gt; &lt;mailto:<a href="mailto:talljimbo@gmail.com">talljimbo@gmail.com</a>&gt;&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;    Oh, you&#39;re right.  I was confusing the manual way of doing<br>
&gt;&gt;    Python-side polymorphism (derived-class holders) with the more<br>
&gt;&gt;    automatic (and better) way you&#39;re doing it (with wrapper).  Your<br>
&gt;&gt;    original code was fine in that regard.<br>
&gt;&gt;<br>
&gt;&gt;    Anyhow, looking closer, here&#39;s what you need to do:<br>
&gt;&gt;<br>
&gt;&gt;      - Put your code back to what it was before I told you to change it.<br>
&gt;&gt;<br>
&gt;&gt;      - Add another line, after the class wrappers:<br>
&gt;&gt;<br>
&gt;&gt;    register_ptr_to_python&lt; boost::shared_ptr&lt;__Communicatable&gt; &gt;();<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;    That explicitly registers a shared_ptr converter for Communicatable.<br>
&gt;&gt;    I&#39;m not sure why Boost.Python doesn&#39;t automatically do that when you<br>
&gt;&gt;    register converters for its derived classes (those are registered by<br>
&gt;&gt;    putting the shared_pr types in the template parameters to class_).<br>
&gt;&gt;      It might just be an oversight, or it might be that doing the base<br>
&gt;&gt;    class registration automatically would cause problems in some contexts.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; The appears to do the trick.  I&#39;m wondering--how do you figure out stuff<br>
&gt;&gt; like that?  That isn&#39;t the kind of thing that could have just occurred<br>
&gt;&gt; to me.<br>
&gt;&gt;<br>
&gt;<br>
&gt; To be honest, it&#39;s probably just a result of having stared at the Boost.Python internals a lot while writing extensions for it.  Ideally, that&#39;s not something every user would have to do - it&#39;s a great library, but the tutorial documentation does not go very deep, and the reference docs are only good if you know what you&#39;re looking for.  So just keep mailing the list :)<br>

&gt;<br>
&gt; Another great way to learn more advance Boost.Python usage is to run Py++.  Even if you don&#39;t use it to produce your final wrappers (I generally don&#39;t), looking at the output can teach you a lot of new tricks.<br>

&gt;</p>
<p>I will have to look at it in the next few days, although I fear it may be an adventure on my real project.<br></p>
<p>&gt; The important bit of knowledge in this case is that putting a shared_ptr type in the template args to class_ does more than just register a to-python converter for shared_ptrs.  It also causes new instances created in Python to be held in a shared_ptr.  That&#39;s necessary in your case because you&#39;re using enable_shared_from_this, but usually it isn&#39;t if you just want to be able to return things by shared_ptr.  So I usually use register_ptr_to_python on all my classes instead, and that&#39;s why I was already familiar with it.</p>

<p>Jim,</p>
<p>Would using register_ptr_to_python explicitly and consistently instead of the online shared_ptr declaration potentially eliminate some side-effects?  I cannot yet isolate why my real app crashes in python when it tries to do an eval into one of my wrappers.<br>
</p>