[C++-sig] boost python and shared_ptr
Denis
frankinshtein at bk.ru
Sun Apr 19 15:12:32 CEST 2009
Hi, sorry for my English,
but I hope you will understand and help me find solution.
Thanks!
there are C++ (pseudo) code:
class A
{
public:
void test()
{
printf(__FUNCTION__);
}
}
shared_ptr<A> gA;
shared_ptr<A> GetA()
{
return gA;
}
//wrapping code:
class_<A, shared_ptr<A> , boost::noncopyable> ("A")
.def("test", &A::test) ;
def("getA", GetA);
and Python code:
a = GetA()
a.test() #works
proxy = weakref.proxy(a)
proxy.test() #works
del a
proxy.test() # failed!!!
#but object is still live in C++
please help me fix it.
I know it is not Python/Boost bug, it is correct behaviour.
What I want?
I want to create PyObject for every object from C++ and save it inside
of my C++ class.
something like this(pseudocode):
class A { object _self; };
if (a->_self == 0)
a->_self = makePyObjectForExistingClass(this)
return _self
and this PyObject should be deleted automatically when object will die
in C++
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090419/70e3420f/attachment.htm>
More information about the Cplusplus-sig
mailing list