Re: [pygccxml-development] Parameter passing, ownership semantics
Brought to you by:
mbaas,
roman_yakovenko
From: Gustavo C. <gjc...@gm...> - 2007-02-18 18:20:56
|
On 2/18/07, Roman Yakovenko <rom...@gm...> wrote: > > On 2/18/07, Gustavo Carneiro <gjc...@gm...> wrote: > > Take this program, where Simulator and EventImpl are C++ classes > wrapped > > by Py++ / boost python: > > > > class MyEvent(EventImpl): > > > > def Notify(self, *args): > > print "Notify!", args > > > > > > ev = MyEvent() > > t1 = Seconds(1) > > Simulator.Schedule(t1, ev) > > Simulator.Run() > > > > There's a memory error here because 'ev' is passed into Simulator, > which > > takes ownership of the value and eventually calls delete on C++ > counterpart > > to 'ev'. valgrind says that Address 0xsomething is 8 bytes inside the > > object allocated by boost python. > > > > If, OTOH, I do "Simulator.Schedule(Seconds(1), MyEvent())", then the > > python objects are prematurely destroyed, and another memory error > occurs . > > > > I notice that Py++ "call policies" are always related to the return > value; > > I don't see how to customize the parameter passing aspect of it all. > > > > Any advice is appreciated. Thanks in advance. > > I don't fully understand your situation. Take a look on this FAQ( > http://boost.org/libs/python/doc/v2/faq.html#ownership ) > > Does it help? Yes, it seems to match my problem. Now, trying to implement the advice I stumble upon the "Make sure the C++ object is held by auto_ptr" part, which I have no idea how to do. How do I tell Py++ to do that? If not, please describe your situation with some C++ code. > > If it do help, than you can use "function transformation" feature to > create the wrapper. > > ( > http://language-binding.net/pyplusplus/documentation/functions/transformation/built_in/built_in.html > ) That doesn't seem to help; I don't know enough of Py++ internals to be able to my own function transformation in useful time. -- Gustavo J. A. M. Carneiro "The universe is always one step beyond logic." |