Re: [pygccxml-development] Parameter passing, ownership semantics
Brought to you by:
mbaas,
roman_yakovenko
From: Gustavo C. <gjc...@gm...> - 2007-02-20 00:03:17
|
On 2/19/07, Roman Yakovenko <rom...@gm...> wrote: > > Hi. Unfortunately I reproduced the error and was not able to fix it > :-(((((. Hey, thanks a lot anyway; it is now a problem in boost, but you solved the Py++ part of the problem with commendable speed. There is something I don't understand and I think this is Boost.Pythonbug. > > I do made some progress. > > 1. When you derive Python class from a C++ one you have to define __init__ > > method, otherwise your code will not work: Since when does a subclass have to define __init__ in order to get the parent class __init__ called? What you say goes against all my python knowledge... class MyEvent(EventImpl): > def __init__( self ): > EventImpl.__init__( self ) > > def Notify(self): > print "Notify!" > > 2. I did small research for you. Read this post: > http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/1331901 > and take a look on Boost.Python unit tests: > > http://boost.cvs.sourceforge.net/boost/boost/libs/python/test/auto_ptr.cpp?view=markup > > http://boost.cvs.sourceforge.net/boost/boost/libs/python/test/auto_ptr.py?view=markup > > What I found is: > The ownership is really transfered. You can check this using simple > technique: Add new function to EventImpl: > virtual std::string class_name() const { return "EventImpl"; } > Add free function: > std::string get_class_name( const std::auto_ptr<EventImpl>& e > ){ > if( e.get() ){ > return e->class_name(); > } > else{ > return "no object"; > } > } > You will get the answer "no object", after "Schedule" call. > So, may be you don't have to delete the Python object. I can't help it; I can't prevent the programmer from deleting the object prematurely; it's out of my control. I will submit the bug to the Boost.Python mailing list, hope somebody will > be able to help. Thanks, I will subscribe to that list too. -- Gustavo J. A. M. Carneiro "The universe is always one step beyond logic." |