Re: [C++-sig] Boost::Python Reference Counting

2014-05-20 Thread Jim Bosch
On Tue, May 20, 2014 at 3:26 PM, Wojciech Mamrak wrote: > In your code, after the call del(container), Element::_container is a > dangling pointer. Using > > .def("getElement", &Container::getElement, return_internal_reference<>()) > > should prevent the deletion of container for as long as eleme

Re: [C++-sig] Boost::Python Reference Counting

2014-05-20 Thread Wojciech Mamrak
In your code, after the call del(container), Element::_container is a dangling pointer. Using .def("getElement", &Container::getElement, return_internal_reference<>()) should prevent the deletion of container for as long as element variable will be alive, me understands (ties lifetime of _contein

Re: [C++-sig] Boost::Python Reference Counting

2014-05-20 Thread Jaedyn Draper
Upon a bit of further reflection on this topic, I realized my suggestion is doing something silly. struct Element { Element(const Container * c, boost::python::object obj) : _container(c), containerPyObj(obj) { } std::string name() const; const Container * _container; boost::pyt

Re: [C++-sig] Boost::Python Reference Counting

2014-05-20 Thread Jim Bosch
I think what you want is the with_custodian_and_ward CallPolicy: http://www.boost.org/doc/libs/1_55_0/libs/python/doc/v2/with_custodian_and_ward.html I can never remember the details of how to invoke it, so I don't have an example ready to go that solves your specific problem, but hopefully the d

Re: [C++-sig] Boost::Python Reference Counting

2014-05-20 Thread Jaedyn Draper
std::shared_ptr and similar types can also be used like so: boost::python::class_> But I don't think that would solve the problem because it's a raw pointer to _container being held here. I don't think there's a way to do what you want with raw pointers. The only way I would know of to do that

Re: [C++-sig] Boost::Python Reference Counting

2014-05-20 Thread Neal Becker
laan wrote: > Hi, > > I'm having issues with Boost::Python objects that contain a reference to a > c++ object: > > --- C++ code > > #include > > struct Container; > > struct Element > { > Element(const Container * c) : _container(c) { } > std::string name() const; > const Co

[C++-sig] Boost::Python Reference Counting

2014-05-20 Thread laan
Hi, I'm having issues with Boost::Python objects that contain a reference to a c++ object: --- C++ code #include struct Container; struct Element { Element(const Container * c) : _container(c) { } std::string name() const; const Container * _container; }; struct Container {