[pygccxml-commit] SF.net SVN: pygccxml: [968] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-04-04 21:05:13
|
Revision: 968 http://svn.sourceforge.net/pygccxml/?rev=968&view=rev Author: roman_yakovenko Date: 2007-04-04 14:05:12 -0700 (Wed, 04 Apr 2007) Log Message: ----------- This commit should introduced neccessary functionality to implement "transfer ownership" Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/unittests/data/transfer_ownership_to_be_exported.hpp pyplusplus_dev/unittests/transfer_ownership_old_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/class_declaration.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2007-04-04 20:21:23 UTC (rev 967) +++ pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2007-04-04 21:05:12 UTC (rev 968) @@ -178,14 +178,17 @@ held_type = self._generated_held_type() if self.wrapper: - if not self.target_configuration.boost_python_has_wrapper_held_type \ - or self.declaration.require_self_reference: - args.append( algorithm.create_identifier( self, self.declaration.decl_string ) ) - if self.declaration.require_self_reference: - if not held_type: + if self.declaration.class_type == self.declaration.CLASS_TYPE.WRAPPER: + args.append( self.wrapper.full_name ) + else: + if not self.target_configuration.boost_python_has_wrapper_held_type \ + or self.declaration.require_self_reference: + args.append( algorithm.create_identifier( self, self.declaration.decl_string ) ) + if self.declaration.require_self_reference: + if not held_type: + args.append( self.wrapper.full_name ) + else: args.append( self.wrapper.full_name ) - else: - args.append( self.wrapper.full_name ) else: args.append( algorithm.create_identifier( self, self.declaration.decl_string ) ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-04-04 20:21:23 UTC (rev 967) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-04-04 21:05:12 UTC (rev 968) @@ -177,6 +177,12 @@ class class_t( class_common_details_t , scopedef_wrapper.scopedef_t , declarations.class_t): + + class CLASS_TYPE: + DEFAULT = 'default' + WRAPPER = 'wrapper' + ALL = ( DEFAULT, WRAPPER ) + def __init__(self, *arguments, **keywords): class_common_details_t.__init__( self ) declarations.class_t.__init__(self, *arguments, **keywords ) @@ -195,6 +201,7 @@ self._properties = [] self._redefined_funcs = None self._require_self_reference = False + self._class_type = self.CLASS_TYPE.DEFAULT def _get_redefine_operators( self ): return self._redefine_operators @@ -203,6 +210,14 @@ redefine_operators = property( _get_redefine_operators, _set_redefine_operators , doc="tells Py++ to redefine operators from base class in this class, False by default") + def _get_class_type(self): + return self._class_type + def _set_class_type(self, class_type): + self._class_type = class_type + class_type = property( _get_class_type, _set_class_type + , doc="set this value to CLASS_TYPE.WRAPPER, if you need to transfer ownership of" \ + "polymorphic class" ) + def _get_held_type(self): return self._held_type def _set_held_type(self, held_type): Modified: pyplusplus_dev/unittests/data/transfer_ownership_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/transfer_ownership_to_be_exported.hpp 2007-04-04 20:21:23 UTC (rev 967) +++ pyplusplus_dev/unittests/data/transfer_ownership_to_be_exported.hpp 2007-04-04 21:05:12 UTC (rev 968) @@ -8,7 +8,7 @@ notify(); } protected: - virtual void notify(){}; + virtual void notify() = 0; }; struct do_nothing_t : event_t{ Modified: pyplusplus_dev/unittests/transfer_ownership_old_tester.py =================================================================== --- pyplusplus_dev/unittests/transfer_ownership_old_tester.py 2007-04-04 20:21:23 UTC (rev 967) +++ pyplusplus_dev/unittests/transfer_ownership_old_tester.py 2007-04-04 21:05:12 UTC (rev 968) @@ -11,26 +11,7 @@ from pyplusplus.module_builder import call_policies from pyplusplus import function_transformers as ft -decref_code = \ -""" -virtual ~%(cls)s(){ - Py_DECREF( boost::python::detail::wrapper_base_::get_owner(*this) ); -// if (this->m_pyobj) { -// Py_DECREF(this->m_pyobj); -// this->m_pyobj = 0; -// } -} -""" -incref_code = \ -""" -//if( !this->m_pyobj) { - //this->m_pyobj = boost::python::detail::wrapper_base_::get_owner(*this); - std::cout << "py owner id: " << (int)(boost::python::detail::wrapper_base_::get_owner(*this)); - //Py_INCREF(this->m_pyobj); -//} -""" - impl_conv_code = \ """ boost::python::implicitly_convertible< std::auto_ptr< %(from)s >, std::auto_ptr< %(to)s > >(); @@ -53,18 +34,9 @@ def customize( self, mb ): event_clss = mb.classes( lambda cls: cls.name in ( 'event_t', 'do_nothing_t' ) ) for cls in event_clss: - cls.require_self_reference = True - cls.set_constructors_body( 'Py_INCREF(self); std::cout<< "self: " << (int)(self) << "\\n" << (int)( boost::python::detail::wrapper_base_::get_owner(*this));' ) - cls.add_wrapper_code( decref_code % { 'cls' : cls.wrapper_alias } ) - #~ cls.add_wrapper_code( 'PyObject* m_pyobj;' ) - #~ cls.set_constructors_body( 'm_pyobj=0;' ) - cls.mem_fun( 'notify' ).add_override_precall_code( incref_code ) - #~ cls.mem_fun( 'notify' ).add_default_precall_code( incref_code ) - + cls.class_type = cls.CLASS_TYPE.WRAPPER cls.held_type = 'std::auto_ptr< %s >' % cls.wrapper_alias cls.add_registration_code( register_sptr % 'std::auto_ptr< %s >' % cls.decl_string, False ) - cls.add_registration_code( register_sptr % 'std::auto_ptr< %s >' % cls.wrapper_alias, False ) - #~ cls.held_type = 'std::auto_ptr< %s >' % cls.decl_string cls.add_registration_code( impl_conv_code % { 'from' : cls.wrapper_alias , 'to' : cls.decl_string } , False) @@ -95,6 +67,7 @@ def notify( self ): print 'notify' self.container.append( 1 ) + print '1 was append' print 'test started' notify_data = [] @@ -106,12 +79,12 @@ print 'event was shceduled' print 'event refcount: ', sys.getrefcount( event ) print 'simulator refcount: ', sys.getrefcount( simulator ) - #del event + #~ del event print 'event was deleted' event = simulator.get_event() print 'event was restored via saved reference in simulator: ', id( event ) print 'event refcount: ', sys.getrefcount( simulator.get_event() ) - #print 'call event.notify(): ', simulator.get_event().notify() + print 'call event.notify(): ', simulator.get_event().notify() print 'call simulator.run()' simulator.run() self.failUnless( notify_data[0] == 1 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |