[pygccxml-commit] SF.net SVN: pygccxml:[1534] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2009-01-05 20:35:14
|
Revision: 1534
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1534&view=rev
Author: roman_yakovenko
Date: 2009-01-05 20:35:09 +0000 (Mon, 05 Jan 2009)
Log Message:
-----------
calling convention is taking into account, while generating free functions
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/calldef.py
pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py
pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py
pyplusplus_dev/pyplusplus/code_creators/function_definition.py
pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py
Modified: pygccxml_dev/pygccxml/declarations/calldef.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/calldef.py 2009-01-05 15:07:31 UTC (rev 1533)
+++ pygccxml_dev/pygccxml/declarations/calldef.py 2009-01-05 20:35:09 UTC (rev 1534)
@@ -43,7 +43,7 @@
FASTCALL = 'fastcall'
SYSTEM_DEFAULT = '<<<system default>>>'
- ALL = ( UNKNOWN, CDECL, STDCALL, THISCALL, FASTCALL )
+ all = ( UNKNOWN, CDECL, STDCALL, THISCALL, FASTCALL, SYSTEM_DEFAULT )
pattern = re.compile( r'.*(?:^|\s)(?:__)?(?P<cc>cdecl|stdcall|thiscall|fastcall)(?:__)?.*' )
Modified: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py
===================================================================
--- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py 2009-01-05 15:07:31 UTC (rev 1533)
+++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py 2009-01-05 20:35:09 UTC (rev 1534)
@@ -1,5 +1,7 @@
# This file has been generated by Py++.
+import sys
+
import ctypes
import ctypes_utils
@@ -251,9 +253,7 @@
mfcreator = ctypes_utils.mem_fun_factory( easybmplib, BMFH, "BMFH" )
BMFH._methods_ = { #class non-virtual member functions definition list
- "__init__" : mfcreator.multi_method()
- .register( mfcreator.default_constructor() )
- .finalize(),
+ "__init__" : mfcreator.default_constructor(),
"display" : mfcreator( "void BMFH::display(void)" ),
@@ -277,9 +277,7 @@
mfcreator = ctypes_utils.mem_fun_factory( easybmplib, BMIH, "BMIH" )
BMIH._methods_ = { #class non-virtual member functions definition list
- "__init__" : mfcreator.multi_method()
- .register( mfcreator.default_constructor() )
- .finalize(),
+ "__init__" : mfcreator.default_constructor(),
"display" : mfcreator( "void BMIH::display(void)" ),
@@ -330,9 +328,7 @@
"TellHorizontalDPI" : mfcreator( "int BMP::TellHorizontalDPI(void)", restype=ctypes.c_int ),
- "__init__" : mfcreator.multi_method()
- .register( mfcreator.default_constructor() )
- .finalize(),
+ "__init__" : mfcreator.default_constructor(),
"__del__" : mfcreator.destructor(is_virtual=False),
@@ -372,21 +368,17 @@
}
del mfcreator
-Square = getattr( easybmplib, easybmplib.undecorated_names["double Square(double)"] )
-Square.restype = ctypes.c_double
-Square.argtypes = [ ctypes.c_double ]
+Square_type = ctypes.CFUNCTYPE( ctypes.c_double, ctypes.c_double )
+Square = Square_type( ( easybmplib.undecorated_names["double Square(double)"], easybmplib ) )
-IntSquare = getattr( easybmplib, easybmplib.undecorated_names["int IntSquare(int)"] )
-IntSquare.restype = ctypes.c_int
-IntSquare.argtypes = [ ctypes.c_int ]
+IntSquare_type = ctypes.CFUNCTYPE( ctypes.c_int, ctypes.c_int )
+IntSquare = IntSquare_type( ( easybmplib.undecorated_names["int IntSquare(int)"], easybmplib ) )
-FlipDWORD = getattr( easybmplib, easybmplib.undecorated_names["unsigned int FlipDWORD(unsigned int)"] )
-FlipDWORD.restype = ctypes.c_uint
-FlipDWORD.argtypes = [ ctypes.c_uint ]
+FlipDWORD_type = ctypes.CFUNCTYPE( ctypes.c_uint, ctypes.c_uint )
+FlipDWORD = FlipDWORD_type( ( easybmplib.undecorated_names["unsigned int FlipDWORD(unsigned int)"], easybmplib ) )
-IsBigEndian = getattr( easybmplib, easybmplib.undecorated_names["bool IsBigEndian(void)"] )
-IsBigEndian.restype = ctypes.c_bool
+IsBigEndian_type = ctypes.CFUNCTYPE( ctypes.c_bool )
+IsBigEndian = IsBigEndian_type( ( easybmplib.undecorated_names["bool IsBigEndian(void)"], easybmplib ) )
-FlipWORD = getattr( easybmplib, easybmplib.undecorated_names["unsigned short FlipWORD(unsigned short)"] )
-FlipWORD.restype = ctypes.c_ushort
-FlipWORD.argtypes = [ ctypes.c_ushort ]
+FlipWORD_type = ctypes.CFUNCTYPE( ctypes.c_ushort, ctypes.c_ushort )
+FlipWORD = FlipWORD_type( ( easybmplib.undecorated_names["unsigned short FlipWORD(unsigned short)"], easybmplib ) )
Modified: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py
===================================================================
--- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py 2009-01-05 15:07:31 UTC (rev 1533)
+++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py 2009-01-05 20:35:09 UTC (rev 1534)
@@ -5,10 +5,8 @@
# http://www.boost.org/LICENSE_1_0.txt)
import sys
-import math
import easybmp as pyeasybmp
-pyeasybmp.IntSquare = lambda x: int( math.sqrt( x ) )
def grayscale_example(source, target):
bmp = pyeasybmp.BMP()
@@ -20,15 +18,10 @@
print 'bit depth: ', bmp.TellBitDepth()
print 'number of colors: ', bmp.TellNumberOfColors()
- print bmp.GetPixel( 1,1 )
-
byte = lambda x: 255 & x
for j in range( bmp.TellHeight() ):
- j += 1
for i in range( bmp.TellWidth() ):
- i += 1
- print i, ', ', j
temp = pyeasybmp.IntSquare( bmp.GetPixel(i,j).Red ) \
+ pyeasybmp.IntSquare( bmp.GetPixel(i,j).Green ) \
+ pyeasybmp.IntSquare( bmp.GetPixel(i,j).Blue )
Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2009-01-05 15:07:31 UTC (rev 1533)
+++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2009-01-05 20:35:09 UTC (rev 1534)
@@ -12,7 +12,19 @@
#TODO - unable to call C function, if dll was loaded as CPPDLL
+CCT = declarations.CALLING_CONVENTION_TYPES
+function_prototype_mapping = {
+ CCT.UNKNOWN : 'CFUNCTYPE'
+ , CCT.CDECL : 'CFUNCTYPE'
+ , CCT.STDCALL : 'WINFUNCTYPE'
+ , CCT.THISCALL : 'CPPMETHODTYPE'
+ , CCT.FASTCALL : '<<<fastcall unsupported>>>'
+ , CCT.SYSTEM_DEFAULT : 'CFUNCTYPE'
+}
+
+assert len( function_prototype_mapping ) == len( CCT.all )
+
class METHOD_MODE:
STAND_ALONE = "stand alone"
MULTI_METHOD = "multi method"
@@ -42,14 +54,17 @@
def ftype( self ):
return self.declaration.function_type()
- def join_arguments( self, args ):
+ def join_arguments( self, args, group_in_list=True ):
args_str = ''
arg_separator = ', '
if 1 == len( args ):
args_str = ' ' + args[0] + ' '
else:
args_str = ' ' + arg_separator.join( args ) + ' '
- return '[%s]' % args_str
+ if group_in_list:
+ return '[%s]' % args_str
+ else:
+ return args_str
@property
def mem_fun_factory_var_name( self ):
@@ -61,11 +76,11 @@
else:
return ''
- def argtypes_code(self):
+ def argtypes_code(self, group_in_list=True):
if not self.ftype.arguments_types:
return ''
args = map( ctypes_formatter.as_ctype, self.ftype.arguments_types )
- return self.join_arguments( args )
+ return self.join_arguments( args, group_in_list )
def _get_system_headers_impl( self ):
return []
@@ -76,21 +91,36 @@
callable_definition_t.__init__( self, free_fun )
def _create_impl(self):
+ global function_prototype_mapping
result = []
- 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
- , undecorated_decl_name=self.undecorated_decl_name) )
+ result.append( '%(alias)s_type = ctypes.%(prototype)s( %(restype)s%(argtypes)s )' )
+ result.append( '%(alias)s = %(alias)s_type( ( %(library_var_name)s.undecorated_names["%(undecorated_decl_name)s"], %(library_var_name)s ) )' )
+
restype = self.restype_code()
- if restype:
- result.append( '%(alias)s.restype = %(restype)s'
- % dict( alias=self.declaration.alias, restype=restype ) )
+ argtypes = self.argtypes_code( group_in_list=False )
- argtypes = self.argtypes_code()
- if argtypes:
- result.append( '%(alias)s.argtypes = %(argtypes)s'
- % dict( alias=self.declaration.alias, argtypes=argtypes ) )
+ return os.linesep.join( result ) \
+ % dict( alias=self.declaration.alias
+ , prototype=function_prototype_mapping[ self.declaration.calling_convention ]
+ , restype=self.iif( restype, restype, 'None' )
+ , argtypes=self.iif( argtypes, ',' + argtypes, '' )
+ , library_var_name=self.top_parent.library_var_name
+ , undecorated_decl_name=self.undecorated_decl_name )
+ #~ 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
+ #~ , undecorated_decl_name=self.undecorated_decl_name) )
+ #~ restype = self.restype_code()
+ #~ if restype:
+ #~ result.append( '%(alias)s.restype = %(restype)s'
+ #~ % dict( alias=self.declaration.alias, restype=restype ) )
+
+ #~ argtypes = self.argtypes_code()
+ #~ if argtypes:
+ #~ result.append( '%(alias)s.argtypes = %(argtypes)s'
+ #~ % dict( alias=self.declaration.alias, argtypes=argtypes ) )
+
return os.linesep.join( result )
class init_definition_t( callable_definition_t ):
@@ -111,11 +141,10 @@
tmpl = '"%(undecorated_decl_name)s", argtypes=%(args)s'
if self.method_mode == METHOD_MODE.STAND_ALONE:
tmpl = '%(mfcreator)s( ' + tmpl + ' )'
-
substitue_dict['args'] = self.argtypes_code()
substitue_dict['undecorated_decl_name'] = self.undecorated_decl_name
if self.method_mode == METHOD_MODE.STAND_ALONE:
- tmp = '"%s" : %s' % ( self.declaration.alias, tmpl )
+ tmpl = '"%s" : %s,' % ( self.alias, tmpl )
return tmpl % substitue_dict
#TODO: aliases for a mem fun and const mem fun with the same name should be different
@@ -156,6 +185,12 @@
return self.get_first_callable().alias
def _create_impl(self):
+ #small hack, this class should not be created at all if there is only one callable
+ if len( self.creators ) == 1:
+ if isinstance( self.creators[0], callable_definition_t ):
+ self.creators[0].method_mode = METHOD_MODE.STAND_ALONE
+ return self.creators[0].create()
+
result = []
return_type = self.get_first_callable().ftype.return_type
Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2009-01-05 15:07:31 UTC (rev 1533)
+++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2009-01-05 20:35:09 UTC (rev 1534)
@@ -92,26 +92,26 @@
they_depend_on_me = decls_package.dependency_info_t.they_depend_on_me
for d in included_decls:
d.include()
- self.logger.info( 'including decl %s' % str(d) )
+ self.logger.debug( 'including decl %s' % str(d) )
parent = d.parent
while True:
if isinstance( parent, decls_package.namespace_t ):
break
else:
- self.logger.info( 'including parent class %s' % str(parent) )
+ self.logger.debug( 'including parent class %s' % str(parent) )
parent.ignore = False
parent = parent.parent
for dependency in they_depend_on_me( d ):
- self.logger.info( 'discovered dependency %s' % str(dependency) )
+ self.logger.debug( 'discovered dependency %s' % str(dependency) )
#include declarations, on which exported declarations depend
#I need this for classes, referenced by function arguments
decls_traits = ( decls_package.class_traits, decls_package.class_declaration_traits, decls_package.enum_traits )
for traits in decls_traits:
if traits.is_my_case( dependency ):
- self.logger.info( 'discovered dependency %s - included' % str(dependency) )
+ self.logger.debug( 'discovered dependency %s - included' % str(dependency) )
traits.get_declaration( dependency ).ignore = False
- self.logger.info( 'including decl %s - done' % str(d) )
+ self.logger.debug( 'including decl %s - done' % str(d) )
def build_code_creator( self, library_path, doc_extractor=None ):
creator = creators_factory.ctypes_creator_t( self.global_ns
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|