when I call python's function with pointer as an argument in boost.python,
there are some troubles in destructor. The following is a sample code
#include <boost/python.hpp>#include <boost/python/module.hpp>#include
<boost/python/def.hpp>#include <string>#include <iostream>using
namespace boost::python;
class A {public:
A() {
std::cout<< "A start"<<std::endl;
}
~A() {std::cout<< "A end" <<std::endl;}}class B {public:
B() { aa=new A; }
~B() { delete aa; }
void run(object ct) {
_obj=ct(); //creat a python object
_obj.attr("fun1")(aa); //call a function named "fun1" with a
pointer arg
_obj.attr("fun2")(aa); //call a function named "fun2" with a
pointer arg
}
A *aa;
object _obj;}
BOOST_PYTHON_MODULE(ctopy){
class_<A> ("A",init<>())
;
class_<b> ("B",init<>())
.def("run",&B::run)
;}
python:
import ctopyclass tc:
def fun1(self,tt):
print "fun1"
def fun2(self,tt):
print "fun2"
bb=ctopy.D()
bb.run(tc)
this result:
A start
fun1
A end
fun2
A end
A end
note:
The "A end" has been printed three.I try it in "valgrind",there are some
errors.I just want to run the destructor once.How to do?
_______________________________________________
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig