[pygccxml-development] Parameter passing, ownership semantics
Brought to you by:
mbaas,
roman_yakovenko
From: Gustavo C. <gjc...@gm...> - 2007-02-18 15:09:26
|
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. -- Gustavo J. A. M. Carneiro "The universe is always one step beyond logic." |