[pygccxml-commit] SF.net SVN: pygccxml:[1387] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-08-08 14:32:00
|
Revision: 1387 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1387&view=rev Author: roman_yakovenko Date: 2008-08-08 14:32:06 +0000 (Fri, 08 Aug 2008) Log Message: ----------- adding new call policy, return_addressof, for better integration with ctypes Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/call_policies.py pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py pyplusplus_dev/pyplusplus/module_builder/call_policies.py pyplusplus_dev/unittests/test_all.py Modified: pyplusplus_dev/pyplusplus/code_repository/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/call_policies.py 2008-08-08 12:18:18 UTC (rev 1386) +++ pyplusplus_dev/pyplusplus/code_repository/call_policies.py 2008-08-08 14:32:06 UTC (rev 1387) @@ -23,10 +23,13 @@ #define call_policies_pyplusplus_hpp__ #include "boost/python.hpp" +#include "boost/cstdint.hpp" #include "boost/mpl/int.hpp" #include "boost/function.hpp" +#include "boost/utility/addressof.hpp" +#include "boost/type_traits/is_same.hpp" #include "boost/python/object/class_detail.hpp" -#include "boost/type_traits/is_same.hpp" + namespace pyplusplus{ namespace call_policies{ namespace bpl = boost::python; @@ -37,19 +40,19 @@ template< typename T> static void deallocate_array(T*){} }; - + struct delete_{ template< typename T> static void deallocate_array(T* arr){ delete[] arr; } - }; - + }; + }/*memory_managers*/ namespace detail{ - + struct make_value_holder{ template <class T> @@ -62,7 +65,6 @@ return bpl::incref( p_value.ptr() ); } } - }; template <class R> @@ -72,25 +74,66 @@ # endif ; +struct make_addressof_holder{ + + template <class T> + static PyObject* execute(T* p){ + if (p == 0){ + return bpl::detail::none(); + } + else{ + boost::uint32_t addressof_p = reinterpret_cast< boost::uint32_t >( p ); + bpl::object p_address( addressof_p ); + return bpl::incref( p_address.ptr() ); + } + } + +}; + +template <class R> +struct return_addressof_value_requires_a_pointer_return_type +# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) +{} +# endif +; + + } //detail struct return_pointee_value{ template <class T> struct apply{ - + BOOST_STATIC_CONSTANT( bool, ok = boost::is_pointer<T>::value ); - + typedef typename boost::mpl::if_c< ok , bpl::to_python_indirect<T, detail::make_value_holder> , detail::return_pointee_value_requires_a_pointer_return_type<T> >::type type; - + }; }; +struct return_addressof{ + + template <class T> + struct apply{ + + BOOST_STATIC_CONSTANT( bool, ok = boost::is_pointer<T>::value ); + + typedef typename boost::mpl::if_c< + ok + , bpl::to_python_indirect<T, detail::make_addressof_holder> + , detail::return_addressof_value_requires_a_pointer_return_type<T> + >::type type; + + }; + +}; + template< typename CallPolicies, class T > bpl::object make_object( T x ){ //constructs object using CallPolicies result_converter @@ -131,7 +174,7 @@ BOOST_STATIC_CONSTANT( bool, ok = boost::is_pointer<T>::value ); typedef details::as_tuple_impl<size, MemoryManager, MakeObjectCallPolicies> type; }; - + }; } /*arrays*/ Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2008-08-08 12:18:18 UTC (rev 1386) +++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2008-08-08 14:32:06 UTC (rev 1387) @@ -60,6 +60,7 @@ from call_policies import return_opaque_pointer from call_policies import return_value_policy from call_policies import return_pointee_value +from call_policies import return_addressof from call_policies import is_return_opaque_pointer_policy from call_policies import custom_call_policies_t from call_policies import custom_call_policies Modified: pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2008-08-08 12:18:18 UTC (rev 1386) +++ pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2008-08-08 14:32:06 UTC (rev 1387) @@ -195,7 +195,7 @@ return [ str( self.custodian ), str( self.ward ) ] def with_custodian_and_ward( custodian, ward, base=None): - """create boost::python::with_custodian_and_ward call policies code generator""" + """create boost::python::with_custodian_and_ward call policies code generator""" return with_custodian_and_ward_t( custodian, ward, base ) class with_custodian_and_ward_postcall_t( with_custodian_and_ward_t ): @@ -207,11 +207,11 @@ return '::boost::python::with_custodian_and_ward_postcall' def with_custodian_and_ward_postcall( custodian, ward, base=None): - """create boost::python::with_custodian_and_ward_postcall call policies code generator""" + """create boost::python::with_custodian_and_ward_postcall call policies code generator""" return with_custodian_and_ward_postcall_t( custodian, ward, base ) class return_value_policy_t( compound_policy_t ): - """implements code generation for boost::python::return_value_policy call policies""" + """implements code generation for boost::python::return_value_policy call policies""" def __init__( self, result_converter_generator, base=None): compound_policy_t.__init__( self, base ) self._result_converter_generator = result_converter_generator @@ -235,12 +235,13 @@ def is_predefined( self ): """Returns True if call policy is defined in Boost.Python library, False otherwise""" + global return_addressof global return_pointee_value - if self.result_converter_generator == return_pointee_value: + if self.result_converter_generator in (return_pointee_value, return_addressof ): return False else: return True - + @property def header_file(self): """Return name of the header file to be included""" @@ -257,9 +258,10 @@ return_by_value = '::boost::python::return_by_value' return_opaque_pointer = '::boost::python::return_opaque_pointer' return_pointee_value = '::pyplusplus::call_policies::return_pointee_value' +return_addressof = '::pyplusplus::call_policies::return_addressof' def return_value_policy( result_converter_generator, base=None): - """create boost::python::return_value_policy call policies code generator""" + """create boost::python::return_value_policy call policies code generator""" return return_value_policy_t( result_converter_generator, base ) def is_return_opaque_pointer_policy( policy ): @@ -293,13 +295,13 @@ class memory_managers: """implements code generation for Py++ defined memory managers - - For complete documentation and usage example see http://language-binding.net/pyplusplus/documentation/functions/call_policies.html + + For complete documentation and usage example see http://language-binding.net/pyplusplus/documentation/functions/call_policies.html """ none = 'none' delete_ = 'delete_' all = [ none, delete_ ] - + @staticmethod def create( manager, function_creator=None): mem_manager = 'pyplusplus::call_policies::memory_managers::' + manager @@ -309,7 +311,7 @@ class convert_array_to_tuple_t( compound_policy_t ): """implements code generation for Py++ defined "as_tuple" value policy - + For complete documentation and usage example see http://language-binding.net/pyplusplus/documentation/functions/call_policies.html """ def __init__( self, array_size, memory_manager, make_object_call_policies=None, base=None): @@ -317,7 +319,7 @@ self._array_size = array_size self._memory_manager = memory_manager self._make_objec_call_policies = make_object_call_policies - + def is_predefined( self ): """Returns True if call policy is defined in Boost.Python library, False otherwise""" return False @@ -359,14 +361,14 @@ if function_creator: as_tuple = algorithm.create_identifier( function_creator, as_tuple ) return [ declarations.templates.join( as_tuple, as_tuple_args ) ] - + def convert_array_to_tuple( array_size, memory_manager, make_object_call_policies=None, base=None ): - """create boost::python::return_value_policy< py++::as_tuple > call policies code generator""" + """create boost::python::return_value_policy< py++::as_tuple > call policies code generator""" return convert_array_to_tuple_t( array_size, memory_manager, make_object_call_policies, base ) class return_range_t( call_policy_t ): """implements code generation for Py++ defined "return_range" call policies - + For complete documentation and usage example see http://language-binding.net/pyplusplus/documentation/functions/call_policies.html """ HEADER_FILE = "__return_range.pypp.hpp" @@ -409,14 +411,14 @@ if not self.value_policies.is_default(): args.append( self.value_policies.create_type() ) return declarations.templates.join( name, args ) - + def return_range( function, get_size_class, value_policies=None ): - """create Py++ defined return_range call policies code generator""" + """create Py++ defined return_range call policies code generator""" r_type = function.return_type if not declarations.is_pointer( r_type ): raise TypeError( 'Function "%s" return type should be pointer, got "%s"' % r_type.decl_string ) - + value_type = declarations.remove_pointer( r_type ) if None is value_policies: if python_traits.is_immutable( value_type ): @@ -424,4 +426,4 @@ else: raise RuntimeError( "return_range call policies requieres specification of value_policies" ) return return_range_t( get_size_class, value_type, value_policies ) - + Modified: pyplusplus_dev/pyplusplus/module_builder/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/call_policies.py 2008-08-08 12:18:18 UTC (rev 1386) +++ pyplusplus_dev/pyplusplus/module_builder/call_policies.py 2008-08-08 14:32:06 UTC (rev 1387) @@ -18,6 +18,7 @@ from pyplusplus.decl_wrappers import return_opaque_pointer from pyplusplus.decl_wrappers import return_value_policy from pyplusplus.decl_wrappers import return_pointee_value +from pyplusplus.decl_wrappers import return_addressof from pyplusplus.decl_wrappers import custom_call_policies from pyplusplus.decl_wrappers import convert_array_to_tuple from pyplusplus.decl_wrappers import memory_managers Modified: pyplusplus_dev/unittests/test_all.py =================================================================== --- pyplusplus_dev/unittests/test_all.py 2008-08-08 12:18:18 UTC (rev 1386) +++ pyplusplus_dev/unittests/test_all.py 2008-08-08 14:32:06 UTC (rev 1387) @@ -105,6 +105,8 @@ import inner_tmpl_class_tester import bug_covariant_returns_tester import embeded_tester +import unions_tester +import cp_return_addressof_tester #import ogre_generate_tester testers = [ @@ -198,6 +200,8 @@ , inner_tmpl_class_tester , bug_covariant_returns_tester , embeded_tester + , unions_tester + , cp_return_addressof_tester # , ogre_generate_tester too much time ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |