def test_convert_sources_to_c_files(self): eci = ExternalCompilationInfo( separate_module_sources=['xxx'], separate_module_files=['x.c'], ) cache_dir = udir.join('test_convert_sources').ensure(dir=1) neweci = eci.convert_sources_to_files(cache_dir) assert not neweci.separate_module_sources res = neweci.separate_module_files assert len(res) == 2 assert res[0] == 'x.c' assert str(res[1]).startswith(str(cache_dir)) e = ExternalCompilationInfo() assert e.convert_sources_to_files() is e
def test_convert_sources_to_c_files(self): eci = ExternalCompilationInfo( separate_module_sources = ['xxx'], separate_module_files = ['x.c'], ) cache_dir = udir.join('test_convert_sources').ensure(dir=1) neweci = eci.convert_sources_to_files(cache_dir) assert not neweci.separate_module_sources res = neweci.separate_module_files assert len(res) == 2 assert res[0] == 'x.c' assert str(res[1]).startswith(str(cache_dir)) e = ExternalCompilationInfo() assert e.convert_sources_to_files() is e
def compile_extension_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). """ state = space.fromcache(State) api_library = state.api_lib if sys.platform == 'win32': kwds["libraries"] = [api_library] # '%s' undefined; assuming extern returning int kwds["compile_extra"] = ["/we4013"] # prevent linking with PythonXX.lib w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2] kwds["link_extra"] = ["/NODEFAULTLIB:Python%d%d.lib" % (space.int_w(w_maj), space.int_w(w_min))] elif sys.platform == 'darwin': kwds["link_files"] = [str(api_library + '.dylib')] else: kwds["link_files"] = [str(api_library + '.so')] if sys.platform.startswith('linux'): kwds["compile_extra"]=["-Werror=implicit-function-declaration", "-g", "-O0"] kwds["link_extra"]=["-g"] modname = modname.split('.')[-1] eci = ExternalCompilationInfo( 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_extension_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). """ state = space.fromcache(State) api_library = state.api_lib if sys.platform == 'win32': kwds["libraries"] = [api_library] # '%s' undefined; assuming extern returning int kwds["compile_extra"] = ["/we4013"] # prevent linking with PythonXX.lib w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2] kwds["link_extra"] = [ "/NODEFAULTLIB:Python%d%d.lib" % (space.int_w(w_maj), space.int_w(w_min)) ] elif sys.platform == 'darwin': kwds["link_files"] = [str(api_library + '.dylib')] else: kwds["link_files"] = [str(api_library + '.so')] if sys.platform.startswith('linux'): kwds["compile_extra"] = [ "-Werror=implicit-function-declaration", "-g", "-O0" ] kwds["link_extra"] = ["-g"] modname = modname.split('.')[-1] eci = ExternalCompilationInfo(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)
cdir = py.path.local(cdir) eci = ExternalCompilationInfo( include_dirs = [cdir], includes = ['src/stacklet/stacklet.h'], separate_module_files = [cdir / 'src' / 'stacklet' / 'stacklet.c'], ) if 'masm' in dir(eci.platform): # Microsoft compiler if is_emulated_long: asmsrc = 'switch_x64_msvc.asm' else: asmsrc = 'switch_x86_msvc.asm' eci.separate_module_files += (cdir / 'src' / 'stacklet' / asmsrc, ) rffi_platform.verify_eci(eci.convert_sources_to_files()) def llexternal(name, args, result, **kwds): return rffi.llexternal(name, args, result, compilation_info=eci, _nowrapper=True, **kwds) # ----- types ----- handle = rffi.COpaquePtr(typedef='stacklet_handle', compilation_info=eci) thread_handle = rffi.COpaquePtr(typedef='stacklet_thread_handle', compilation_info=eci) run_fn = lltype.Ptr(lltype.FuncType([handle, llmemory.Address], handle)) # ----- constants ----- null_handle = lltype.nullptr(handle.TO)
cdir = py.path.local(cdir) eci = ExternalCompilationInfo( include_dirs=[cdir], includes=['src/stacklet/stacklet.h'], separate_module_files=[cdir / 'src' / 'stacklet' / 'stacklet.c'], ) if 'masm' in dir(eci.platform): # Microsoft compiler if is_emulated_long: asmsrc = 'switch_x64_msvc.asm' else: asmsrc = 'switch_x86_msvc.asm' eci.separate_module_files += (cdir / 'src' / 'stacklet' / asmsrc, ) rffi_platform.verify_eci(eci.convert_sources_to_files()) def llexternal(name, args, result, **kwds): return rffi.llexternal(name, args, result, compilation_info=eci, _nowrapper=True, **kwds) # ----- types ----- handle = rffi.COpaquePtr(typedef='stacklet_handle', compilation_info=eci) thread_handle = rffi.COpaquePtr(typedef='stacklet_thread_handle',
def make_vs_attach_eci(): # The COM interface to the Debugger has to be compiled as a .cpp file by # Visual C. So we generate the source and then add a commandline switch # to treat this source file as C++ import os eci = ExternalCompilationInfo(post_include_bits=[ """ #ifdef __cplusplus extern "C" { #endif RPY_EXPORTED void AttachToVS(); #ifdef __cplusplus } #endif """ ], separate_module_sources=[ """ #import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only named_guids extern "C" RPY_EXPORTED void AttachToVS() { CoInitialize(0); HRESULT hr; CLSID Clsid; CLSIDFromProgID(L"VisualStudio.DTE", &Clsid); IUnknown *Unknown; if (FAILED(GetActiveObject(Clsid, 0, &Unknown))) { puts("Could not attach to Visual Studio (is it not running?"); return; } EnvDTE::_DTE *Interface; hr = Unknown->QueryInterface(&Interface); if (FAILED(GetActiveObject(Clsid, 0, &Unknown))) { puts("Could not open COM interface to Visual Studio (no permissions?)"); return; } EnvDTE::Debugger *Debugger; puts("Waiting for Visual Studio Debugger to become idle"); while (FAILED(Interface->get_Debugger(&Debugger))); EnvDTE::Processes *Processes; while (FAILED(Debugger->get_LocalProcesses(&Processes))); long Count = 0; if (FAILED(Processes->get_Count(&Count))) { puts("Cannot query Process count"); } for (int i = 0; i <= Count; i++) { EnvDTE::Process *Process; if (FAILED(Processes->Item(variant_t(i), &Process))) { continue; } long ProcessID; while (FAILED(Process->get_ProcessID(&ProcessID))); if (ProcessID == GetProcessId(GetCurrentProcess())) { printf("Found process ID %d\\n", ProcessID); Process->Attach(); Debugger->Break(false); CoUninitialize(); return; } } } """ ]) eci = eci.convert_sources_to_files() d = eci._copy_attributes() cfile = d['separate_module_files'][0] cppfile = cfile.replace(".c", "_vsdebug.cpp") os.rename(cfile, cppfile) d['separate_module_files'] = [cppfile] return ExternalCompilationInfo(**d)