On Wed, Aug 5, 2009 at 10:33 AM, Ravi<lists_r...@lavabit.com> wrote: > On Sunday 02 August 2009 11:44:22 Haoyu Bai wrote: >> So could anyone share your experience with this issue, provide some >> test case or anymore information about this issue? I will try to solve >> it. > > I haven't been able to spend any time on this. But the general approach I > wanted to check is as follows: > > Test 1 (to check registry operation): > 1. Use an example which embeds (not extends) python. > 2. Register a type X to be converted to C++ type XC. > 3. Perform some operations to verify that step 2 works. > 4. Call PyFinalize. > 5. Restart python vising PyInit... > 6. Check that X does not convert to XC. > > Test 2 (to check object cleanup): > 1. Hold weak pointers to some shared_ptr<T> objects exposed to python. > 2. Call PyFinalize. > 3. Ensure that all the weak_ptrs point to deleted objects. > > Let me think about this some more. Please try pinging Dave A directly to make > sure he has no tests for you to try. > > Regards, > Ravi >
Hi, I have the attached file to check the two test cases you mentioned, or see it at here: http://pastebin.org/7108 The test #1 failed. Registered converters are not cleaned up during Py_Finalize. But test #2 not fail, shared_ptr object is properly destroyed. I think the registration issue is not hard to fix. But is the "crash" mentioned in BPL manual still valid? We still can't produce any crash. I'll check with Dave. Thanks! -- Haoyu Bai School of Computing, National University of Singapore.
#include <iostream> #include <Python.h> #include <boost/python.hpp> #include <boost/shared_ptr.hpp> using namespace boost::python; class Foo { public: void foo() { std::cout<<"foo--"<<std::endl; } ~Foo() { std::cout << "Destructing Foo..." << std::endl; } }; int runfoo(Foo &h) { h.foo(); return 0; } BOOST_PYTHON_MODULE(foo) { class_<Foo, boost::shared_ptr<Foo> >("Foo") .def("foo", &Foo::foo) ; } BOOST_PYTHON_MODULE(runfoo) { def("runfoo", runfoo); } void session1() { using namespace boost::python; if(PyImport_AppendInittab("foo", initfoo) == -1) throw "error initfoo"; if(PyImport_AppendInittab("runfoo", initrunfoo) == -1) throw "error initrunfoo"; Py_Initialize(); object main = import("__main__"); object hooge = import("foo"); object runfoo = import("runfoo"); runfoo.attr("runfoo")(object(Foo())); Py_Finalize(); } void session2() { using namespace boost::python; if(PyImport_AppendInittab("runfoo", initrunfoo) == -1) throw "fooeee"; Py_Initialize(); object runfoo = import("runfoo"); runfoo.attr("runfoo")(object(Foo())); Py_Finalize(); } void test_register() { if ( handle_exception(session1) || handle_exception(session2) ) { if (PyErr_Occurred()) { PyErr_Print(); } } } void test_sharedptr() { using namespace boost::python; std::cout << "Testing test_sharedptr..." << std::endl; { Py_Initialize(); object main = import("__main__"); main.attr("foo") = boost::shared_ptr<Foo>(new Foo()); } std::cout << "Before call Py_Finalize" << std::endl; Py_Finalize(); // At here, the Foo object properly destroyed. std::cout << "Called Py_Finalize" << std::endl; } int main() { test_register(); test_sharedptr(); return 0; }
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig