[C++-sig] boost python and shared_ptr
Renato Araujo
renatox at gmail.com
Sun Apr 19 17:12:56 CEST 2009
I don't know if this is exactly what do you want.
take a look in this doc:
http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#xref
BR
On Sun, Apr 19, 2009 at 10:12 AM, Denis <frankinshtein at bk.ru> wrote:
> 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!
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
--
Renato Araujo Oliveira Filho
More information about the Cplusplus-sig
mailing list