[pygccxml-commit] SF.net SVN: pygccxml:[1513] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-12-29 14:02:43
|
Revision: 1513 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1513&view=rev Author: roman_yakovenko Date: 2008-12-29 14:02:40 +0000 (Mon, 29 Dec 2008) Log Message: ----------- adding few basic ctypes code creators Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/class_introduction.py pyplusplus_dev/pyplusplus/code_creators/fields_definition.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py pyplusplus_dev/pyplusplus/code_creators/import_.py pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py pyplusplus_dev/pyplusplus/code_creators/methods_definition.py pyplusplus_dev/pyplusplus/code_repository/__init__.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/pyplusplus/file_writers/writer.py pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp pyplusplus_dev/unittests/data/ctypes_pof/mydll.h Added Paths: ----------- pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj Removed Paths: ------------- pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -150,9 +150,14 @@ from name_mappings import name_mappings_t from namespace_as_pyclass import namespace_as_pyclass_t from class_introduction import class_introduction_t +from class_introduction import class_declaration_introduction_t from mem_fun_introduction import mem_fun_introduction_t from mem_fun_introduction import vmem_fun_introduction_t +from mem_fun_introduction import constructor_introduction_t +from mem_fun_introduction import destructor_introduction_t + + from fields_definition import fields_definition_t from embedded_code_repository import embedded_code_repository_t from methods_definition import methods_definition_t -from function_definition import c_function_definition_t +from function_definition import function_definition_t Modified: pyplusplus_dev/pyplusplus/code_creators/class_introduction.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_introduction.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/class_introduction.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -5,6 +5,7 @@ import os import compound +import code_creator import declaration_based from pygccxml import declarations @@ -17,8 +18,6 @@ result = [] result.append( "class %s(ctypes.Structure):" % self.alias ) result.append( self.indent( '"""class %s"""' % self.decl_identifier ) ) - result.append( self.indent( '#_fields_ = [] <-- class member variables definition list' ) ) - result.append( self.indent( '#_methods_ = {} <-- class non-virtual member functions definition list' ) ) if self.creators: result.append( self.indent( '' ) ) result.append( compound.compound_t.create_internal_code( self.creators ) ) @@ -31,3 +30,24 @@ def _get_system_headers_impl( self ): return [] + + +class class_declaration_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, class_declaration ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, class_declaration ) + + def _create_impl(self): + result = [] + result.append( "class %s(ctypes.Structure):" % self.alias ) + result.append( self.indent( '"""class declaration %s"""' % self.decl_identifier ) ) + result.append( self.indent( '_fields_ = []' ) ) + + if isinstance( self.declaration.parent, declarations.namespace_t ) \ + and self.declaration.parent is not self.declaration.top_parent: #not a global namespace + result.append( '%(ns_full_name)s = %(name)s' + % dict( ns_full_name=self.complete_py_name, name=self.alias )) + return os.linesep.join( result ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/code_creators/fields_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/fields_definition.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/fields_definition.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -8,6 +8,11 @@ import declaration_based from pygccxml import declarations +#TODO: don't hide public member variables +#TODO: how _fields_ should be defined in a class hierarchy +#TODO: fix 64bit issue with calculating vtable pointer size + + class fields_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, class_ ): code_creator.code_creator_t.__init__(self) @@ -15,13 +20,11 @@ def _create_impl(self): result = [] - result.append( '%(complete_py_name)s._fields_ = [ #class member variables definition list' - % dict( complete_py_name=self.complete_py_name ) ) + result.append( '%(complete_py_name)s._fields_ = [ #class %(decl_identifier)s' + % dict( complete_py_name=self.complete_py_name + , decl_identifier=self.decl_identifier) ) if self.declaration.has_vtable: result.append( self.indent( '("_vtable_", ctypes.POINTER(ctypes.c_void_p)),' ) ) - result.append( self.indent( "#TODO: don't hide public member variables" ) ) - result.append( self.indent( "#TODO: how _fields_ should be defined in a class hierarchy" ) ) - result.append( self.indent( "#TODO: fix 64bit issue with calculating vtable pointer size" ) ) result.append( self.indent( '("__hidden__", ctypes.c_char * %d),' % ( self.declaration.byte_size - 4*int(self.declaration.has_vtable) ) ) ) result.append( ']' ) Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -9,14 +9,9 @@ import declaration_based from pygccxml import declarations -""" -BSCGetBaseArray = _libraries['msbsc70.dll'].BSCGetBaseArray -BSCGetBaseArray.restype = BOOL -BSCGetBaseArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IINST)), POINTER(ULONG)] +#TODO - unable to call C function, if dll was loaded as CPPDLL -""" - -class c_function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): +class function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, free_fun ): code_creator.code_creator_t.__init__(self) declaration_based.declaration_based_t.__init__( self, free_fun ) @@ -37,11 +32,10 @@ def _create_impl(self): result = [] - result.append( '#%s' % self.undecorated_decl_name ) - result.append( '#TODO - unable to call C function, if dll was loaded as CPPDLL' ) - result.append( '%(alias)s = %(library_var_name)s.%(alias)s' + result.append( '%(alias)s = getattr( %(library_var_name)s, %(library_var_name)s.undecorated_names["%(undecorated_decl_name)s"] )' % dict( alias=self.declaration.alias - , library_var_name=self.top_parent.library_var_name ) ) + , library_var_name=self.top_parent.library_var_name + , undecorated_decl_name=self.undecorated_decl_name) ) if not declarations.is_void( self.ftype.return_type ): result.append( '%(alias)s.restype = %(restype)s' Modified: pyplusplus_dev/pyplusplus/code_creators/import_.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/import_.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/import_.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -3,6 +3,7 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import os import code_creator import include_directories @@ -14,7 +15,7 @@ self._module_name = module_name def _create_impl(self): - return 'import %(module)s' % dict( module=self._module_name ) + return 'import %(module)s' % dict( module=os.path.splitext(self._module_name)[0] ) def _get_system_headers_impl( self ): return [] Modified: pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -39,3 +39,33 @@ def _get_system_headers_impl( self ): return [] + +class constructor_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, constructor ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, constructor ) + + def _create_impl(self): + tmpl = ['def __init__( self, *args ):'] + tmpl.append( self.indent('"""%(name)s"""') ) + tmpl.append( self.indent("return self._methods_['__init__']( ctypes.byref( self ), *args )") ) + return os.linesep.join( tmpl ) \ + % dict( alias=self.declaration.alias, name=self.undecorated_decl_name ) + + def _get_system_headers_impl( self ): + return [] + +class destructor_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, constructor ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, constructor ) + + def _create_impl(self): + tmpl = ['def __del__( self ):'] + tmpl.append( self.indent('"""%(name)s"""') ) + tmpl.append( self.indent("return self._methods_['__del__']( ctypes.byref( self ) )") ) + return os.linesep.join( tmpl ) \ + % dict( name=self.undecorated_decl_name ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/code_creators/methods_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -21,9 +21,9 @@ result = [] scope = declarations.algorithm.declaration_path( self.declaration ) del scope[0] #del :: from the global namespace + del scope[-1] #del self from the list - - result.append( '%(mem_fun_factory_var_name)s = mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s", "%(ns)s" )' + result.append( '%(mem_fun_factory_var_name)s = ctypes_utils.mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s", "%(ns)s" )' % dict( mem_fun_factory_var_name=self.mem_fun_factory_var_name , library_var_name=self.top_parent.library_var_name , complete_py_name=self.complete_py_name Modified: pyplusplus_dev/pyplusplus/code_repository/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/__init__.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_repository/__init__.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -19,7 +19,7 @@ import convenience import return_range import call_policies -import ctypes_cpp_utils +import ctypes_utils import ctypes_integration all = [ array_1 @@ -28,7 +28,7 @@ , call_policies , named_tuple , return_range - , ctypes_cpp_utils + , ctypes_utils , ctypes_integration ] headers = map( lambda f: f.file_name, all ) Deleted: pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -1,92 +0,0 @@ -# Copyright 2004-2008 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -file_name = "ctypes_cpp_utils.py" - -license = \ -"""# Copyright 2004-2008 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -""" - - -code = \ -""" -# what is the best way to treat overloaded constructors -class mem_fun_callable( object ): - def __init__(self, dll, name, restype=None, argtypes=None ): - self.name = name - self.func = getattr( dll, dll.undecorated_names[name] ) - self.func.restype = restype - self.func.argtypes = argtypes - - def __call__(self, *args, **keywd ): - return self.func( *args, **keywd ) - -class mem_fun_factory( object ): - def __init__( self, dll, wrapper, class_name, namespace='' ): - self.dll = dll - self.namespace = namespace - self.class_name = class_name - self.this_type = ctypes.POINTER( wrapper ) - - def __call__( self, name, **keywd ): - if 'argtypes' not in keywd: - keywd['argtypes'] = [ self.this_type ] - else: - keywd['argtypes'].insert( 0, self.this_type ) - return mem_fun_callable( self.dll, name, **keywd ) - - def __get_ns_name(self): - if self.namespace: - return self.namespace + '::' - else: - return '' - - def default_constructor( self ): - return self( '%(ns)s%(class_name)s::%(class_name)s(void)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) ) - - def constructor( self, argtypes_str, **keywd ): - return self( '%(ns)s%(class_name)s::%(class_name)s(%(args)s)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name - , args=argtypes_str ) - , **keywd ) - - def copy_constructor( self ): - return self( '%(ns)s%(class_name)s::%(class_name)s(%(class_name)s const &)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) - , argtypes=[self.this_type] ) - - def destructor( self ): - return self( '%(ns)s%(class_name)s::~%(class_name)s(void)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) ) - - def operator_assign( self ): - return self( '%(ns)s%(class_name)s & %(class_name)s::operator=(%(class_name)s const &)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) - , restype=self.this_type - , argtypes=[self.this_type] ) - - def method( self, name, restype_str=None, argtypes_str=None, **keywd ): - if None is restype_str: - restype_str = 'void' - if None is argtypes_str: - argtypes_str = 'void' - - return self( '%(return_)s %(ns)s%(class_name)s::%(method_name)s(%(args)s)' - % dict( return_=restype_str - , ns=self.__get_ns_name() - , class_name=self.class_name - , method_name=name - , args=argtypes_str ) - , **keywd ) -""" Copied: pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py (from rev 1512, pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py) =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -0,0 +1,121 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +file_name = "ctypes_utils.py" + +code = \ +"""# Copyright 2004-2008 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import ctypes + +# what is the best way to treat overloaded constructors +class native_callable( object ): + def __init__(self, dll, name, restype=None, argtypes=None ): + self.name = name + self.func = getattr( dll, dll.undecorated_names[name] ) + self.func.restype = restype + self.func.argtypes = argtypes + + def __call__(self, *args, **keywd ): + return self.func( *args, **keywd ) + +class native_overloaded_callable( object ): + def __init__(self, restype=None ): + self.__functions = {} # argtypes : function + self.restype = restype + + def register( self, dll, name, argtypes=None ): + f = getattr( dll, dll.undecorated_names[name] ) + f.restype = self.restype + f.argtypes = argtypes + self.__functions[ argtypes ] = f + return self + + def register_callable( self, callable ): + #TODO: check restype + self.__functions[ tuple(callable.func.argtypes) ] = callable.func + return self + + def __call__( self, *args ): + types = None + if args: + types = tuple(arg.__class__ for arg in args) + f = self.__functions.get(types) + if f is None: + return f(*args) + else: + raise TypeError("no match") + +def multi_method( restype=None ): + return native_overloaded_callable( restype ) + +class mem_fun_factory( object ): + def __init__( self, dll, wrapper, class_name, namespace='' ): + self.dll = dll + self.namespace = namespace + self.class_name = class_name + self.this_type = ctypes.POINTER( wrapper ) + + def __call__( self, name, **keywd ): + if 'argtypes' not in keywd: + keywd['argtypes'] = [ self.this_type ] + else: + keywd['argtypes'].insert( 0, self.this_type ) + return native_callable( self.dll, name, **keywd ) + + def __get_ns_name(self): + if self.namespace: + return self.namespace + '::' + else: + return '' + + def default_constructor( self ): + return self( '%(ns)s%(class_name)s::%(class_name)s(void)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) ) + + def constructor( self, argtypes_str, **keywd ): + return self( '%(ns)s%(class_name)s::%(class_name)s(%(args)s)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name + , args=argtypes_str ) + , **keywd ) + + def copy_constructor( self ): + return self( '%(ns)s%(class_name)s::%(class_name)s(%(ns)s%(class_name)s const &)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) + , argtypes=[self.this_type] ) + + def destructor( self ): + return self( '%(ns)s%(class_name)s::~%(class_name)s(void)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) ) + + def operator_assign( self ): + return self( '%(ns)s%(class_name)s & %(class_name)s::operator=(%(class_name)s const &)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) + , restype=self.this_type + , argtypes=[self.this_type] ) + + def method( self, name, restype_str=None, argtypes_str=None, **keywd ): + if None is restype_str: + restype_str = 'void' + if None is argtypes_str: + argtypes_str = 'void' + + return self( '%(return_)s %(ns)s%(class_name)s::%(method_name)s(%(args)s)' + % dict( return_=restype_str + , ns=self.__get_ns_name() + , class_name=self.class_name + , method_name=name + , args=argtypes_str ) + , **keywd ) + +""" Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -32,14 +32,22 @@ self.module = code_creators.ctypes_module_t( global_ns ) self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) + #bookmark for class introductions self.__class_ccs = code_creators.bookmark_t() + #bookmark for class deinitions + self.__class_defs_ccs = code_creators.bookmark_t() #~ prepared_decls = self.__prepare_decls( global_ns, doc_extractor ) #~ self.__decls = sort_algorithms.sort( prepared_decls ) self.curr_decl = global_ns self.curr_code_creator = self.module + #mapping between class declaration and class introduction code creator self.__class2introduction = {} + #mapping between namespace and its code creator self.__namespace2pyclass = {} + #set of all included namespaces + #~ self.__included_nss = set() + #~ for decl in self.global_ns def __print_readme( self, decl ): readme = decl.readme() @@ -109,9 +117,13 @@ # Invoke the appropriate visit_*() method on all decls ccc = self.curr_code_creator ccc.adopt_creator( code_creators.import_t( 'ctypes' ) ) + ccc.adopt_creator( code_creators.import_t( code_repository.ctypes_utils.file_name ) ) + ccc.adopt_creator( code_creators.separator_t() ) + ccc.adopt_creator( code_creators.library_reference_t( self.__library_path ) ) ccc.adopt_creator( code_creators.name_mappings_t( self.__exported_symbols ) ) + ccc.adopt_creator( code_creators.separator_t() ) #adding namespaces global_ns_cc = code_creators.bookmark_t() @@ -127,7 +139,7 @@ if self.__contains_exported( class_ ): self.__add_class_introductions( self.__class_ccs, class_ ) - ccc.adopt_creator( code_creators.embedded_code_repository_t( code_repository.ctypes_cpp_utils ) ) + ccc.adopt_creator( self.__class_defs_ccs ) declarations.apply_visitor( self, self.curr_decl ) @@ -148,9 +160,16 @@ def visit_constructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] + has_constructor = filter( lambda cc: isinstance( cc, code_creators.constructor_introduction_t ) + , cls_intro_cc.creators ) + if not has_constructor: + cls_intro_cc.adopt_creator( code_creators.constructor_introduction_t( self.curr_decl ) ) def visit_destructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] + cls_intro_cc.adopt_creator( code_creators.destructor_introduction_t( self.curr_decl ) ) def visit_member_operator( self ): self.__dependencies_manager.add_exported( self.curr_decl ) @@ -162,22 +181,23 @@ self.__dependencies_manager.add_exported( self.curr_decl ) if self.curr_decl.name in self.__exported_symbols \ and self.curr_decl.name == self.__exported_symbols[ self.curr_decl.name ]: - #we deal with c function - self.curr_code_creator.adopt_creator( code_creators.c_function_definition_t( self.curr_decl ) ) + return #it is notpossible to call C function from CPPDLL + else: + self.curr_code_creator.adopt_creator( code_creators.function_definition_t( self.curr_decl ) ) def visit_free_operator( self ): self.__dependencies_manager.add_exported( self.curr_decl ) def visit_class_declaration(self ): self.__dependencies_manager.add_exported( self.curr_decl ) - ci_creator = code_creators.class_introduction_t( self.curr_decl ) - self.curr_code_creator.adopt_creator( ci_creator ) + ci_creator = code_creators.class_declaration_introduction_t( self.curr_decl ) + self.__class_ccs.adopt_creator( ci_creator ) def visit_class(self): self.__dependencies_manager.add_exported( self.curr_decl ) #fields definition should be recursive using the visitor - self.curr_code_creator.adopt_creator( code_creators.fields_definition_t( self.curr_decl ) ) - self.curr_code_creator.adopt_creator( code_creators.methods_definition_t( self.curr_decl ) ) + self.__class_defs_ccs.adopt_creator( code_creators.fields_definition_t( self.curr_decl ) ) + self.__class_defs_ccs.adopt_creator( code_creators.methods_definition_t( self.curr_decl ) ) class_ = self.curr_decl for decl in self.curr_decl.decls( recursive=False, allow_empty=True ): if self.__should_generate_code( decl ): @@ -195,6 +215,8 @@ self.__dependencies_manager.add_exported( self.curr_decl ) def visit_namespace(self ): + if not self.__contains_exported( self.curr_decl ): + return if self.global_ns is not self.curr_decl: ns_creator = code_creators.namespace_as_pyclass_t( self.curr_decl ) self.__namespace2pyclass[ self.curr_decl ] = ns_creator Modified: pyplusplus_dev/pyplusplus/file_writers/writer.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/writer.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/file_writers/writer.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -71,9 +71,14 @@ if cr.file_name in system_headers: #check whether file from code repository is used self.write_file( os.path.join( dir, cr.file_name ), cr.code ) - #named_tuple.py is a special case :-( - self.write_file( os.path.join( dir, code_repository.named_tuple.file_name ) - , code_repository.named_tuple.code ) + #Python files are a special case + if isinstance( self.extmodule, code_creators.bpmodule_t ): + self.write_file( os.path.join( dir, code_repository.named_tuple.file_name ) + , code_repository.named_tuple.code ) + else: + self.write_file( os.path.join( dir, code_repository.ctypes_utils.file_name ) + , code_repository.ctypes_utils.code ) + @staticmethod def write_file( fpath, content, files_sum_repository=None, encoding='ascii' ): """Write a source file. Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -92,7 +92,6 @@ they_depend_on_us = decls_package.dependency_info_t.they_depend_on_us included_decls.update( they_depend_on_us( included_decls ) ) for d in included_decls: - print str(d) d.include() if isinstance( d, decls_package.class_t ): d.top_class.include() Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -27,8 +27,23 @@ sys.path.append( autoconfig.build_directory ) import ctypes_pof #the following code fails - difference in the calling conventions - self.failUnless( ctypes_pof.identity( int(111) ) == 111 ) + print ctypes_pof.identity_cpp( int(111) ) + self.failUnless( ctypes_pof.identity_cpp( int(111) ) == 111 ) + #~ def test_bsc( self ): + #~ root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' + #~ mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] + #~ , os.path.join( root, 'msbsc70.dll' ), autoconfig.cxx_parsers_cfg.gccxml ) + mb.print_declarations() + #~ mb.build_code_creator( self.symbols_file ) + #~ mb.write_module( os.path.join( root, 'bsc.py' ) ) + #~ #mb.code_creator.create() + sys.path.append( autoconfig.build_directory ) + import ctypes_pof + print ctypes_pof.identity( 23 ) + self.failUnless( ctypes_pof.identity( 23 ) == 23 ) + + def create_suite(): suite = unittest.TestSuite() if 'win' in sys.platform: Added: pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj 2008-12-29 14:02:40 UTC (rev 1513) @@ -0,0 +1,187 @@ +<?xml version="1.0" encoding="windows-1255"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="mydll" + ProjectGUID="{0B9466BC-60F8-4FC2-A1A9-6A01577690E5}" + RootNamespace="mydll" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + BrowseInformation="1" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + GenerateMapFile="true" + MapFileName="$(TargetDir)$(TargetName).map" + MapExports="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath=".\mydll.cpp" + > + </File> + <File + RelativePath=".\mydll.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Copied: pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj (from rev 1512, pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj) =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj 2008-12-29 14:02:40 UTC (rev 1513) @@ -0,0 +1,182 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="mydll" + ProjectGUID="{E7A34C45-534F-43A6-AF95-3CA2428619E2}" + RootNamespace="mydll" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="2" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + BrowseInformation="1" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + GenerateMapFile="true" + MapExports="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath=".\mydll.cpp" + > + </File> + <File + RelativePath=".\mydll.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-29 14:02:40 UTC (rev 1513) @@ -49,6 +49,8 @@ int identity( int some_data){ return some_data;} +int identity_cpp( int data){ return data; } + BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2008-12-29 14:02:40 UTC (rev 1513) @@ -31,4 +31,6 @@ int __declspec(dllexport) identity( int ); -} \ No newline at end of file +} + +int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Deleted: pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj 2008-12-29 14:02:40 UTC (rev 1513) @@ -1,182 +0,0 @@ -<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="9.00" - Name="mydll" - ProjectGUID="{E7A34C45-534F-43A6-AF95-3CA2428619E2}" - RootNamespace="mydll" - Keyword="Win32Proj" - TargetFrameworkVersion="196613" - > - <Platforms> - <Platform - Name="Win32" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="3" - UsePrecompiledHeader="2" - WarningLevel="3" - DebugInformationFormat="4" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="2" - GenerateDebugInformation="true" - SubSystem="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - EnableIntrinsicFunctions="true" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - RuntimeLibrary="2" - EnableFunctionLevelLinking="true" - UsePrecompiledHeader="0" - BrowseInformation="1" - WarningLevel="3" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="1" - GenerateDebugInformation="true" - GenerateMapFile="true" - MapExports="true" - SubSystem="2" - OptimizeReferences="2" - EnableCOMDATFolding="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <File - RelativePath=".\mydll.cpp" - > - </File> - <File - RelativePath=".\mydll.h" - > - </File> - </Files> - <Globals> - </Globals> -</VisualStudioProject> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |