def compile_module(space, modname, **kwds): """ Build an extension module and return the filename of the resulting native code file. modname is the name of the module, possibly including dots if it is a module inside a package. Any extra keyword arguments are passed on to ExternalCompilationInfo to build the module (so specify your source with one of those). """ modname = modname.split('.')[-1] eci = ExternalCompilationInfo( export_symbols=['init%s' % (modname,)], include_dirs=api.include_dirs, **kwds ) eci = eci.convert_sources_to_files() dirname = (udir/uniquemodulename('module')).ensure(dir=1) soname = platform.platform.compile( [], eci, outputfilename=str(dirname/modname), standalone=False) from pypy.module.imp.importing import get_so_extension pydname = soname.new(purebasename=modname, ext=get_so_extension(space)) soname.rename(pydname) return str(pydname)
def compile_module(space, modname, **kwds): """ Build an extension module and return the filename of the resulting native code file. modname is the name of the module, possibly including dots if it is a module inside a package. Any extra keyword arguments are passed on to ExternalCompilationInfo to build the module (so specify your source with one of those). """ modname = modname.split('.')[-1] eci = ExternalCompilationInfo(export_symbols=['init%s' % (modname, )], include_dirs=api.include_dirs, **kwds) eci = eci.convert_sources_to_files() dirname = (udir / uniquemodulename('module')).ensure(dir=1) soname = platform.platform.compile([], eci, outputfilename=str(dirname / modname), standalone=False) from pypy.module.imp.importing import get_so_extension pydname = soname.new(purebasename=modname, ext=get_so_extension(space)) soname.rename(pydname) return str(pydname)
def compile_db(db): enable_fast_compilation() # for testing modulename = uniquemodulename('testing') targetdir = udir.join(modulename).ensure(dir=1) gen_source(db, modulename, str(targetdir), defines={'COUNT_OP_MALLOCS': 1}) m = make_module_from_c(targetdir.join(modulename+'.c'), include_dirs = [os.path.dirname(autopath.this_dir)], libraries = db.gcpolicy.gc_libraries()) return m
def generate_source(self, db=None, defines={}): assert self.c_source_filename is None translator = self.translator if db is None: db = self.build_database() pf = self.getentrypointptr() pfname = db.get(pf) if self.modulename is None: self.modulename = uniquemodulename('testing') modulename = self.modulename targetdir = udir.ensure(modulename, dir=1) self.targetdir = targetdir defines = defines.copy() if self.config.translation.countmallocs: defines['COUNT_OP_MALLOCS'] = 1 if self.config.translation.sandbox: defines['RPY_SANDBOXED'] = 1 if CBuilder.have___thread is None: CBuilder.have___thread = check_under_under_thread() if not self.standalone: assert not self.config.translation.instrument cfile, extra = gen_source(db, modulename, targetdir, self.eci, defines = defines) else: if self.config.translation.instrument: defines['INSTRUMENT'] = 1 if CBuilder.have___thread: if not self.config.translation.no__thread: defines['USE___THREAD'] = 1 # explicitely include python.h and exceptions.h # XXX for now, we always include Python.h from distutils import sysconfig python_inc = sysconfig.get_python_inc() pypy_include_dir = autopath.this_dir self.eci = self.eci.merge(ExternalCompilationInfo( include_dirs=[python_inc, pypy_include_dir], )) cfile, extra = gen_source_standalone(db, modulename, targetdir, self.eci, entrypointname = pfname, defines = defines) self.c_source_filename = py.path.local(cfile) self.extrafiles = extra if self.standalone: self.gen_makefile(targetdir) return cfile
def generate_source(self, db=None, defines={}, exe_name=None): assert self.c_source_filename is None translator = self.translator if db is None: db = self.build_database() pf = self.getentrypointptr() if self.modulename is None: self.modulename = uniquemodulename('testing') modulename = self.modulename targetdir = udir.ensure(modulename, dir=1) if self.config.translation.dont_write_c_files: targetdir = NullPyPathLocal(targetdir) self.targetdir = targetdir defines = defines.copy() if self.config.translation.countmallocs: defines['COUNT_OP_MALLOCS'] = 1 if self.config.translation.sandbox: defines['RPY_SANDBOXED'] = 1 if CBuilder.have___thread is None: CBuilder.have___thread = self.translator.platform.check___thread() if not self.standalone: assert not self.config.translation.instrument if self.cpython_extension: defines['PYPY_CPYTHON_EXTENSION'] = 1 else: defines['PYPY_STANDALONE'] = db.get(pf) if self.config.translation.instrument: defines['INSTRUMENT'] = 1 if CBuilder.have___thread: if not self.config.translation.no__thread: defines['USE___THREAD'] = 1 if self.config.translation.shared: defines['PYPY_MAIN_FUNCTION'] = "pypy_main_startup" self.eci = self.eci.merge( ExternalCompilationInfo( export_symbols=["pypy_main_startup"])) self.eci, cfile, extra = gen_source(db, modulename, targetdir, self.eci, defines=defines, split=self.split) self.c_source_filename = py.path.local(cfile) self.extrafiles = self.eventually_copy(extra) self.gen_makefile(targetdir, exe_name=exe_name) return cfile
def generate_source(self, db=None, defines={}): assert self.c_source_filename is None translator = self.translator if db is None: db = self.build_database() pf = self.getentrypointptr() if self.modulename is None: self.modulename = uniquemodulename('testing') modulename = self.modulename targetdir = udir.ensure(modulename, dir=1) self.targetdir = targetdir defines = defines.copy() if self.config.translation.countmallocs: defines['COUNT_OP_MALLOCS'] = 1 if self.config.translation.sandbox: defines['RPY_SANDBOXED'] = 1 if CBuilder.have___thread is None: CBuilder.have___thread = self.translator.platform.check___thread() if not self.standalone: assert not self.config.translation.instrument self.eci, cfile, extra = gen_source(db, modulename, targetdir, self.eci, defines=defines, split=self.split) else: pfname = db.get(pf) if self.config.translation.instrument: defines['INSTRUMENT'] = 1 if CBuilder.have___thread: if not self.config.translation.no__thread: defines['USE___THREAD'] = 1 self.eci, cfile, extra = gen_source_standalone( db, modulename, targetdir, self.eci, entrypointname=pfname, defines=defines) self.c_source_filename = py.path.local(cfile) self.extrafiles = self.eventually_copy(extra) self.gen_makefile(targetdir) return cfile
def generate_source(self, db=None, defines={}, exe_name=None): assert self.c_source_filename is None translator = self.translator if db is None: db = self.build_database() pf = self.getentrypointptr() if self.modulename is None: self.modulename = uniquemodulename('testing') modulename = self.modulename targetdir = udir.ensure(modulename, dir=1) self.targetdir = targetdir defines = defines.copy() if self.config.translation.countmallocs: defines['COUNT_OP_MALLOCS'] = 1 if self.config.translation.sandbox: defines['RPY_SANDBOXED'] = 1 if CBuilder.have___thread is None: CBuilder.have___thread = self.translator.platform.check___thread() if not self.standalone: assert not self.config.translation.instrument self.eci, cfile, extra = gen_source(db, modulename, targetdir, self.eci, defines = defines, split=self.split) else: pfname = db.get(pf) if self.config.translation.instrument: defines['INSTRUMENT'] = 1 if CBuilder.have___thread: if not self.config.translation.no__thread: defines['USE___THREAD'] = 1 if self.config.translation.shared: defines['PYPY_MAIN_FUNCTION'] = "pypy_main_startup" self.eci = self.eci.merge(ExternalCompilationInfo( export_symbols=["pypy_main_startup"])) self.eci, cfile, extra = gen_source_standalone(db, modulename, targetdir, self.eci, entrypointname = pfname, defines = defines) self.c_source_filename = py.path.local(cfile) self.extrafiles = self.eventually_copy(extra) self.gen_makefile(targetdir, exe_name=exe_name) return cfile
def generate_source(self, db=None, defines={}): assert self.c_source_filename is None translator = self.translator if db is None: db = self.build_database() pf = self.getentrypointptr() pfname = db.get(pf) if self.modulename is None: self.modulename = uniquemodulename('testing') modulename = self.modulename targetdir = udir.ensure(modulename, dir=1) self.targetdir = targetdir defines = defines.copy() if self.config.translation.countmallocs: defines['COUNT_OP_MALLOCS'] = 1 if CBuilder.have___thread is None: CBuilder.have___thread = check_under_under_thread() if not self.standalone: assert not self.config.translation.instrument from pypy.translator.c.symboltable import SymbolTable # XXX fix symboltable #self.symboltable = SymbolTable() cfile, extra, extraincludes = gen_source(db, modulename, targetdir, defines = defines, exports = self.exports, symboltable = self.symboltable) else: if self.config.translation.instrument: defines['INSTRUMENT'] = 1 if CBuilder.have___thread: if not self.config.translation.no__thread: defines['USE___THREAD'] = 1 cfile, extra, extraincludes = \ gen_source_standalone(db, modulename, targetdir, entrypointname = pfname, defines = defines) self.c_source_filename = py.path.local(cfile) self.extrafiles = extra self.extraincludes = extraincludes.keys() if self.standalone: self.gen_makefile(targetdir) return cfile
def generate_source(self, db=None, defines={}): assert self.c_source_filename is None translator = self.translator if db is None: db = self.build_database() pf = self.getentrypointptr() pfname = db.get(pf) if self.modulename is None: self.modulename = uniquemodulename('testing') modulename = self.modulename targetdir = udir.ensure(modulename, dir=1) self.targetdir = targetdir defines = defines.copy() if self.config.translation.countmallocs: defines['COUNT_OP_MALLOCS'] = 1 if self.config.translation.sandbox: defines['RPY_SANDBOXED'] = 1 if CBuilder.have___thread is None: CBuilder.have___thread = self.translator.platform.check___thread() if not self.standalone: assert not self.config.translation.instrument self.eci, cfile, extra = gen_source(db, modulename, targetdir, self.eci, defines = defines) else: if self.config.translation.instrument: defines['INSTRUMENT'] = 1 if CBuilder.have___thread: if not self.config.translation.no__thread: defines['USE___THREAD'] = 1 self.eci, cfile, extra = gen_source_standalone(db, modulename, targetdir, self.eci, entrypointname = pfname, defines = defines) self.c_source_filename = py.path.local(cfile) self.extrafiles = self.eventually_copy(extra) self.gen_makefile(targetdir) return cfile