<div dir="ltr"><div>Hi Stefan,</div><div><br></div><div> I tried to create minimal tests and it turned out that there might be two separate issues here: one related to memory management and other to subclassing C++ classes in Python (i will post the subclassing example in separate mail).</div><div> </div><div> Running code below as-is works fine and i can see printed message generated by ‘A’ class destructor. However commenting out line ‘reset_callback()’ in Python code will lead to a segfault and also no call to ‘A’ class destructor occur. Thoughts? </div><div><br></div><div> Thanks,</div><div><br></div><div><br></div><div>Ernie.</div><div><br></div><div><br></div><div>Python code: ———————— </div><div>from callback2 import *</div><div><br></div><div>a1 = A()</div><div><a href="http://a1.info">a1.info</a>()</div><div>set_callback(a1)</div><div>test_callback()</div><div>reset_callback() </div><div><br></div><div>C++ code: —————————— </div><div>include <iostream></div><div>#include <boost/shared_ptr.hpp></div><div>#include <boost/python.hpp></div><div><br></div><div>class A</div><div>{</div><div>public:</div><div><span class="" style="white-space:pre"> </span>virtual ~A() { std::cout << "A destructor for object: " << this << std::endl; }</div><div><br></div><div><span class="" style="white-space:pre"> </span>virtual void info() { std::cout << "C++ A info for object" << this << std::endl; }</div><div>};</div><div><br></div><div>static boost::shared_ptr<A> current_callback;</div><div><br></div><div>void set_callback(boost::shared_ptr<A> a) {current_callback = a; }</div><div><br></div><div>void reset_callback() { current_callback = boost::shared_ptr<A>(); }</div><div><br></div><div>void test_callback()</div><div>{</div><div><span class="" style="white-space:pre"> </span>std::cout << "test_callback: ";</div><div><span class="" style="white-space:pre"> </span>if(current_callback) current_callback->info();</div><div><span class="" style="white-space:pre"> </span>else std::cout << "Callback is NULL!" << std::endl;</div><div>}</div><div><br></div><div><br></div><div>BOOST_PYTHON_MODULE(callback2)</div><div>{</div><div><span class="" style="white-space:pre"> </span>boost::python::class_<A, boost::shared_ptr< A >, boost::noncopyable>("A")</div><div><span class="" style="white-space:pre"> </span>.def("info", &A::info)</div><div><span class="" style="white-space:pre"> </span>;</div><div><br></div><div><span class="" style="white-space:pre"> </span>boost::python::def("set_callback", set_callback);</div><div><span class="" style="white-space:pre"> </span>boost::python::def("reset_callback", reset_callback);</div><div><span class="" style="white-space:pre"> </span>boost::python::def("test_callback", test_callback);</div><div>}</div><div>————————————————</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 11, 2015 at 12:01 AM, Stefan Seefeld <span dir="ltr"><<a href="mailto:stefan@seefeld.name" target="_blank">stefan@seefeld.name</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10/03/15 11:24 PM, Ernie Lee wrote:<br>
> Hi Stefan,<br>
><br>
> I updated my code so it now use 'boost::shared_ptr' class while<br>
> specifying the held-type and i got exactly the same errors (i guess<br>
> boost did recognize class even in different namespace).<br>
><br>
> Any other theories of what could be wrong? Could it be that Python<br>
> in some cases tries to manage memory directly, disregarding SP layer?<br>
<br>
</span>In that case I suggest you narrow down the failure into a minimal test<br>
case and send that to the list. Otherwise this would be highly<br>
speculative and thus inefficient.<br>
<br>
Regards,<br>
<div class="HOEnZb"><div class="h5"> Stefan<br>
<br>
--<br>
<br>
...ich hab' noch einen Koffer in Berlin...<br>
<br>
_______________________________________________<br>
Cplusplus-sig mailing list<br>
<a href="mailto:Cplusplus-sig@python.org">Cplusplus-sig@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/cplusplus-sig" target="_blank">https://mail.python.org/mailman/listinfo/cplusplus-sig</a><br>
</div></div></blockquote></div><br></div>