Re: [pygccxml-development] Parameter passing, ownership semantics
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2007-02-18 17:36:48
|
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? 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 ) Thanks. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |