[pygccxml-commit] SF.net SVN: pygccxml:[1380] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-07-30 18:23:34
|
Revision: 1380 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1380&view=rev Author: roman_yakovenko Date: 2008-07-30 18:23:40 +0000 (Wed, 30 Jul 2008) Log Message: ----------- small bug fix in expose_address Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py pyplusplus_dev/unittests/data/ft_from_address_to_be_exported.hpp pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp pyplusplus_dev/unittests/ft_from_address_tester.py pyplusplus_dev/unittests/member_variables_tester.py Modified: pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py 2008-07-27 18:43:00 UTC (rev 1379) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py 2008-07-30 18:23:40 UTC (rev 1380) @@ -33,14 +33,22 @@ template< typename TType, typename TMemVarType > boost::uint32_t -addressof( const TType &inst, const TMemVarType TType::* offset){ +addressof( const TType* inst_ptr, const TMemVarType TType::* offset){ + if( !inst_ptr ){ + throw std::runtime_error( "unable to dereference null pointer" ); + } + const TType& inst = *inst_ptr; return boost::uint32_t( boost::addressof( inst.*offset ) ); } template< typename TType > boost::uint32_t -addressof_inst( const TType &inst){ - return boost::uint32_t( boost::addressof( inst ) ); +addressof_inst( const TType* inst_ptr){ + if( !inst_ptr ){ + throw std::runtime_error( "unable to dereference null pointer" ); + } + + return boost::uint32_t( inst_ptr ); } template< typename TType, typename TMemVarType > @@ -50,7 +58,7 @@ namespace pyppc = pyplusplus::convenience; return bpl::make_function( boost::bind( &pyppc::addressof< TType, TMemVarType >, _1, offset ) , bpl::default_call_policies() - , boost::mpl::vector< boost::uint32_t, const TType& >() ); + , boost::mpl::vector< boost::uint32_t, const TType* >() ); } template< typename TType > @@ -60,7 +68,7 @@ namespace pyppc = pyplusplus::convenience; return bpl::make_function( boost::bind( &pyppc::addressof_inst< TType >, _1 ) , bpl::default_call_policies() - , boost::mpl::vector< boost::uint32_t, const TType& >() ); + , boost::mpl::vector< boost::uint32_t, const TType* >() ); } class register_addressof_static_var : public boost::python::def_visitor<register_addressof_static_var> @@ -72,7 +80,7 @@ template< typename TVarType > register_addressof_static_var( const char* name, const TVarType& var ) : m_name( name ) - , m_address( addressof_inst( var ) ) + , m_address( addressof_inst( boost::addressof( var ) ) ) {} template <class classT> Modified: pyplusplus_dev/unittests/data/ft_from_address_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/ft_from_address_to_be_exported.hpp 2008-07-27 18:43:00 UTC (rev 1379) +++ pyplusplus_dev/unittests/data/ft_from_address_to_be_exported.hpp 2008-07-30 18:23:40 UTC (rev 1380) @@ -23,4 +23,24 @@ return result; } +struct ptr_ptr_t{ + + ptr_ptr_t() + : value( new double( 5.9 ) ) + {} + + ~ptr_ptr_t(){ + delete value; + } + + void get_v_address( double** v ){ + if( !v ){ + throw std::runtime_error( "null pointer" ); + *v = value; + } + } + + double* value; +}; + #endif//__ft_from_address_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2008-07-27 18:43:00 UTC (rev 1379) +++ pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2008-07-30 18:23:40 UTC (rev 1380) @@ -163,6 +163,17 @@ static int* none_image; }; + + class Andy{ + protected: + Andy() : userData(NULL) {} + + virtual ~Andy() {} + + public: + void * userData; + }; + } } Modified: pyplusplus_dev/unittests/ft_from_address_tester.py =================================================================== --- pyplusplus_dev/unittests/ft_from_address_tester.py 2008-07-27 18:43:00 UTC (rev 1379) +++ pyplusplus_dev/unittests/ft_from_address_tester.py 2008-07-30 18:23:40 UTC (rev 1380) @@ -24,9 +24,11 @@ , *args ) def customize( self, mb ): - mb.global_ns.calldefs().create_with_signature = True mb.calldef( 'sum_matrix' ).add_transformation( ft.from_address(0) ) + ptr_ptr = mb.class_( 'ptr_ptr_t' ) + ptr_ptr.var( 'value' ).expose_address = True + ptr_ptr.mem_fun( 'get_v_address' ).add_transformation( ft.from_address(0 ) ) def run_tests(self, module): rows = 10 @@ -43,6 +45,16 @@ result = module.sum_matrix( ctypes.addressof( matrix ), rows, columns ) self.failUnless( result == sum ) + ptr = module.ptr_ptr_t() + double_ptr_type = ctypes.POINTER( ctypes.c_double ) + value = double_ptr_type.from_address( ptr.value ) + self.failUnless( value.contents.value == 5.9 ) + dd = double_ptr_type(ctypes.c_double(0.0) ) + print dir( ctypes.pointer( dd ).contents ) + ptr.get_v_address( ctypes.pointer( dd ).contents.value ) + print ptr.value + print dd.contents.value + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) Modified: pyplusplus_dev/unittests/member_variables_tester.py =================================================================== --- pyplusplus_dev/unittests/member_variables_tester.py 2008-07-27 18:43:00 UTC (rev 1379) +++ pyplusplus_dev/unittests/member_variables_tester.py 2008-07-30 18:23:40 UTC (rev 1380) @@ -25,6 +25,7 @@ image = mb.class_( 'image_t' ) image.var( 'data' ).expose_address = True image.var( 'none_image' ).expose_address = True + mb.class_( 'Andy' ).var('userData').expose_address = True def change_default_color( self, module ): module.point.default_color = module.point.color.blue @@ -95,8 +96,8 @@ data_type = ctypes.POINTER( ctypes.c_int ) data = data_type.from_address( image.data ) for j in range(5): - print '%d : %d' % ( j, data[j] ) - + self.failUnless( j == data[j] ) + data_type = ctypes.POINTER( ctypes.c_int ) data = data_type.from_address( module.image_t.none_image ) self.failUnless( 1997 == data.contents.value ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |