Boost C++ Libraries: Ticket #2584: boost::enable_shared_from_this + boost.python library https://svn.boost.org/trac10/ticket/2584 <p> A problem that was raised, on february, on c++-sig mailing list about a problem happening when wrapping classes derived from 'enable_shared_from_this' using boost.python library. </p> <p> The problem is briefly described in this post - including a patch to boost/shared_ptr.hpp that would allow to work around the problem. <a class="ext-link" href="http://mail.python.org/pipermail/cplusplus-sig/2008-February/012973.html"><span class="icon">​</span>http://mail.python.org/pipermail/cplusplus-sig/2008-February/012973.html</a> </p> <p> To make it short, boost.python creates shared_ptr objects, holding the wrapped c++ objects, with a custom deleter managing the python object reference count. This leads to something like that : </p> <p> #include &lt;boost/enable_shared_from_this.hpp&gt; </p> <p> namespace {<br /> </p> <blockquote> <p> class A : public boost::enable_shared_from_this&lt;A&gt;<br /> {<br /> public:<br /> </p> <blockquote> <p> ~A() {};<br /> </p> </blockquote> <p> };<br /> void my_deleter(void*)<br /> {<br /> }<br /> </p> </blockquote> <p> };<br /> BOOST_AUTO_TEST_CASE( test_enable_shared_from_this )<br /> {<br /> </p> <blockquote> <p> boost::shared_ptr&lt;A&gt; a( new A );<br /> {<br /> </p> <blockquote> <p> boost::shared_ptr&lt;A&gt; ater = <br /> </p> <blockquote> <p> boost::shared_ptr&lt;A&gt;( a.get(), my_deleter );<br /> </p> </blockquote> <p> <em> OP patch proposal:<br /> </em> boost::shared_ptr&lt;A&gt; ater = <br /> <em> boost::shared_ptr&lt;A&gt;( a.get(), my_deleter<br /> </em> , boost::dont_enable_shared_from_this() );<br /> BOOST_CHECK( a == ater );<br /> </p> </blockquote> <p> }<br /> boost::shared_ptr&lt;A&gt; abug = a-&gt;shared_from_this(); <em> this throws bad_weak_ptr<br /> </em></p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2584 Trac 1.4.3 trotterdylan@… Tue, 24 Feb 2009 19:13:52 GMT <link>https://svn.boost.org/trac10/ticket/2584#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2584#comment:1</guid> <description> <p> This is a fairly major issue for my Boost.Python project. I'm currently using a patched 1.37 distribution, but I'd like to go back to a standard distribution for 1.39. Is this issue on the radar for that release? </p> </description> <category>Ticket</category> </item> <item> <author>nico_ml@…</author> <pubDate>Wed, 25 Feb 2009 08:36:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2584#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2584#comment:2</guid> <description> <p> I don't know if you're aware of a patch that I've submitted to boost.python, that uses shared_ptr aliasing constructor to fix the problem. </p> <p> <a class="ext-link" href="http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html"><span class="icon">​</span>http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html</a> </p> <p> The patch has been integrated in boost.python svn trunk, but I doubt it has been released in boost 1.38. </p> </description> <category>Ticket</category> </item> <item> <author>trotterdylan@…</author> <pubDate>Wed, 25 Feb 2009 13:31:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2584#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2584#comment:3</guid> <description> <p> Ah! I'm glad to hear it's in the trunk. I have integrated the patch into my 1.37 local installation, but ultimately I'd like to get back to using standard installs. Do you think the patch will be included in 1.39? </p> <p> Thanks! </p> <p> -dt </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Sat, 28 Feb 2009 17:06:28 GMT</pubDate> <title>status, milestone changed https://svn.boost.org/trac10/ticket/2584#comment:4 https://svn.boost.org/trac10/ticket/2584#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.38.0</span> → <span class="trac-field-new">Boost 1.39.0</span> </li> </ul> Ticket Peter Dimov Tue, 03 Mar 2009 19:25:29 GMT <link>https://svn.boost.org/trac10/ticket/2584#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2584#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/51581" title="Fix enable_shared_from_this-related tickets in trunk. Refs #2126. Refs ...">[51581]</a>) Fix enable_shared_from_this-related tickets in trunk. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2126" title="#2126: Bugs: make_shared doesn't work with enable_shared_from_this (closed: fixed)">#2126</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2584" title="#2584: Bugs: boost::enable_shared_from_this + boost.python library (closed: fixed)">#2584</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 05 Mar 2009 23:06:20 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2584#comment:6 https://svn.boost.org/trac10/ticket/2584#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/51632" title="Merge [51581] to release. Fixes #2126. Fixes #2584.">[51632]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/51581" title="Fix enable_shared_from_this-related tickets in trunk. Refs #2126. Refs ...">[51581]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2126" title="#2126: Bugs: make_shared doesn't work with enable_shared_from_this (closed: fixed)">#2126</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2584" title="#2584: Bugs: boost::enable_shared_from_this + boost.python library (closed: fixed)">#2584</a>. </p> Ticket