def generate_ctypes_code( self, file_configuration, symbols_file, compiler_config ):
     try:
         _logging_.loggers.make_inmemory()
         mb = ctypes_module_builder_t( [ file_configuration ], symbols_file, compiler_config )
         mb.build_code_creator( symbols_file )
         code = mb.code_creator.create()
         code = code.replace( '\n\r', '\n' )
         code = code.replace( '\r\n', '\n' )
         warnings = _logging_.loggers.stream.getvalue()
         _logging_.loggers.stream.close()
         return code, warnings
     except Exception, error:
         user_msg = [ 'Error occured during code generation process!' ]
         user_msg.append( 'Error:' )
         user_msg.append( str( error ) )
         return '', '\n'.join( user_msg )
Beispiel #2
0
    def setUp( self ):
        if self.base_name in sys.modules:
            return sys.modules[ self.base_name ]

        binaries_dir = os.path.dirname( self.symbols_file )
        if os.path.exists( binaries_dir ):
            print '\nrmdir ', binaries_dir
            shutil.rmtree( binaries_dir )

        autoconfig.scons_config.compile( self.__build_scons_cmd(), cwd=autoconfig.this_module_dir_path )
        mb = ctypes_module_builder_t( [self.header], self.symbols_file, autoconfig.cxx_parsers_cfg.gccxml )
        self.customize( mb )        
        mb.build_code_creator( self.library_file )
        mb.write_module( os.path.join( self.project_dir, 'binaries', self.base_name + '.py' ) )
        sys.path.insert( 0, os.path.join( self.project_dir, 'binaries' ) )
        __import__( self.base_name )
Beispiel #3
0
    def setUp(self):
        if self.base_name in sys.modules:
            return sys.modules[self.base_name]

        binaries_dir = os.path.dirname(self.symbols_file)
        if os.path.exists(binaries_dir):
            print('\nrmdir ', binaries_dir)
            shutil.rmtree(binaries_dir)

        autoconfig.scons_config.compile(self.__build_scons_cmd(),
                                        cwd=autoconfig.this_module_dir_path)
        mb = ctypes_module_builder_t([self.header], self.symbols_file,
                                     autoconfig.cxx_parsers_cfg.gccxml)
        self.customize(mb)
        mb.build_code_creator(self.library_file)
        mb.write_module(
            os.path.join(self.project_dir, 'binaries', self.base_name + '.py'))
        sys.path.insert(0, os.path.join(self.project_dir, 'binaries'))
        __import__(self.base_name)
Beispiel #4
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t

gccxml_cfg = parser.gccxml_configuration_t(
    gccxml_path=project_env.settings.gccxml_path)

mb = ctypes_module_builder_t([project_env.gmp.header_file],
                             project_env.gmp.symbols_file, gccxml_cfg)

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs(has_varargs).exclude()

#gmp uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
for f in mb.calldefs(lambda x: x.name.startswith('__gmp')):
    f.alias = f.name[2:]

for v in mb.vars(lambda x: x.name.startswith('__gmp')):
    v.alias = v.name[2:]

#those structs are private implementation of FILE
Beispiel #5
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t

gccxml_cfg = parser.gccxml_configuration_t(
    gccxml_path=project_env.settings.gccxml_path,
    include_paths=project_env.libmemcached.include_paths)

mb = ctypes_module_builder_t([project_env.libmemcached.header_file],
                             project_env.libmemcached.symbols_file, gccxml_cfg)

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs(has_varargs).exclude()

#libmemcached uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
#for f in mb.calldefs( lambda x: x.name.startswith('__gmp') ):
#    f.alias = f.name[2:]

#for v in mb.vars( lambda x: x.name.startswith( '__gmp' ) ):
#    v.alias = v.name[2:]
Beispiel #6
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t


gccxml_cfg = parser.gccxml_configuration_t( gccxml_path=project_env.settings.gccxml_path
                                            , include_paths=project_env.libmemcached.include_paths)

mb = ctypes_module_builder_t( [project_env.libmemcached.header_file]
                              , project_env.libmemcached.symbols_file, gccxml_cfg )

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs( has_varargs ).exclude()

#libmemcached uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
#for f in mb.calldefs( lambda x: x.name.startswith('__gmp') ):
#    f.alias = f.name[2:]

#for v in mb.vars( lambda x: x.name.startswith( '__gmp' ) ):
#    v.alias = v.name[2:]
Beispiel #7
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t


gccxml_cfg = parser.gccxml_configuration_t( gccxml_path=project_env.settings.gccxml_path )

mb = ctypes_module_builder_t( [project_env.gmp.header_file], project_env.gmp.symbols_file, gccxml_cfg )

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs( has_varargs ).exclude()

#gmp uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
for f in mb.calldefs( lambda x: x.name.startswith('__gmp') ):
    f.alias = f.name[2:]

for v in mb.vars( lambda x: x.name.startswith( '__gmp' ) ):
    v.alias = v.name[2:]

#those structs are private implementation of FILE
mb.class_( '_IO_FILE' ).opaque = True