def setup(): compile_extra = ['-DRPYTHON_LL2CTYPES', '-DALLOW_SURROGATES=0', '-fPIC'] eci_kwds = dict(include_dirs=[SRC], includes=['utf8.h'], libraries=_libs, compile_extra=compile_extra) # compile the SSE4.1 and AVX version compile_extra.append('-msse4.1') ofile_eci = ExternalCompilationInfo(**eci_kwds) sse4_o, = trans_plaform._compile_o_files([SRC.join('utf8-sse4.c')], ofile_eci) compile_extra.pop() compile_extra.append('-mavx2') ofile_eci = ExternalCompilationInfo(**eci_kwds) avx_o, = trans_plaform._compile_o_files([SRC.join('utf8-avx.c')], ofile_eci) del ofile_eci eci_kwds['separate_module_files'] = [SRC.join('utf8.c')] eci_kwds['link_files'] = [sse4_o.strpath, avx_o.strpath] eci = ExternalCompilationInfo(**eci_kwds) platform.verify_eci(eci) count_utf8_codepoints = rffi.llexternal("fu8_count_utf8_codepoints", [rffi.CCHARP, rffi.SSIZE_T], rffi.SSIZE_T, compilation_info=eci, _nowrapper=True) index2byteposition = rffi.llexternal( "fu8_idx2bytepos", [rffi.SIZE_T, rffi.CCHARP, rffi.SIZE_T, IDXTABP], rffi.SSIZE_T, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def setup(): from rpython.jit.backend import detect_cpu if detect_cpu.autodetect().startswith(detect_cpu.MODEL_S390_64): raise VMProfPlatformUnsupported("rvmprof not supported on" " s390x CPUs for now") compile_extra = ['-DRPYTHON_LL2CTYPES'] platform.verify_eci(ExternalCompilationInfo( compile_extra=compile_extra, **eci_kwds)) eci = global_eci vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def setup(): compile_extra = ['-DRPYTHON_LL2CTYPES'] platform.verify_eci(ExternalCompilationInfo( compile_extra=compile_extra, **eci_kwds)) eci = global_eci vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) vmprof_get_traceback = rffi.llexternal("vmprof_get_traceback", [PVMPROFSTACK, llmemory.Address, rffi.SIGNEDP, lltype.Signed], lltype.Signed, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def setup(): if host_platform.machine() == 's390x': raise VMProfPlatformUnsupported("rvmprof not supported on" " s390x CPUs for now") compile_extra = ['-DRPYTHON_LL2CTYPES'] platform.verify_eci(ExternalCompilationInfo( compile_extra=compile_extra, **eci_kwds)) eci = global_eci vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def setup(): if host_platform.machine() == 's390x': raise VMProfPlatformUnsupported("rvmprof not supported on" " s390x CPUs for now") compile_extra = ['-DRPYTHON_LL2CTYPES'] platform.verify_eci( ExternalCompilationInfo(compile_extra=compile_extra, **eci_kwds)) eci = global_eci vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def setup(): if sys.platform.startswith('linux'): configure_libbacktrace_linux() eci_kwds['compile_extra'].append('-DRPYTHON_LL2CTYPES') platform.verify_eci(ExternalCompilationInfo( **eci_kwds)) eci = global_eci vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.INT, rffi.INT, rffi.CCHARP, rffi.INT], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [rffi.INT, rffi.INT], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) vmprof_get_traceback = rffi.llexternal("vmprof_get_traceback", [PVMPROFSTACK, llmemory.Address, rffi.SIGNEDP, lltype.Signed], lltype.Signed, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def detect_float(): """Check for hardware float support we try to compile a function containing a VFP instruction, and if the compiler accepts it we assume we are fine """ try: rffi_platform.verify_eci(eci) return True except CompilationError: return False
def setup(): if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64): raise VMProfPlatformUnsupported("rvmprof only supports" " x86-64 CPUs for now") ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof') SRC = ROOT.join('src') if sys.platform.startswith('linux'): libs = ['dl'] else: libs = [] eci_kwds = dict( include_dirs=[SRC], includes=['rvmprof.h'], libraries=libs, separate_module_files=[SRC.join('rvmprof.c')], post_include_bits=['#define RPYTHON_VMPROF\n'], ) eci = ExternalCompilationInfo(**eci_kwds) platform.verify_eci( ExternalCompilationInfo(compile_extra=['-DRPYTHON_LL2CTYPES'], **eci_kwds)) vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci) return CInterface(locals())
def setup(): if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64): raise VMProfPlatformUnsupported("rvmprof only supports" " x86-64 CPUs for now") ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof') SRC = ROOT.join('src') if sys.platform.startswith('linux'): libs = ['dl'] else: libs = [] eci_kwds = dict( include_dirs = [SRC], includes = ['rvmprof.h'], libraries = libs, separate_module_files = [SRC.join('rvmprof.c')], post_include_bits=['#define RPYTHON_VMPROF\n'], ) eci = ExternalCompilationInfo(**eci_kwds) platform.verify_eci(ExternalCompilationInfo( compile_extra=['-DRPYTHON_LL2CTYPES'], **eci_kwds)) vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci) return CInterface(locals())
def test_external_lib(): eci = ExternalCompilationInfo(include_dirs=[cdir]) c_source = """ #include "src/precommondefs.h" RPY_EXPORTED int f(int a, int b) { return (a + b); } """ if platform.name == 'msvc': libname = 'libc_lib' else: libname = 'c_lib' tmpdir = udir.join('external_lib').ensure(dir=1) c_file = tmpdir.join('libc_lib.c') c_file.write(c_source) l = platform.compile([c_file], eci, standalone=False) eci = ExternalCompilationInfo(libraries=[libname], library_dirs=[str(tmpdir)]) rffi_platform.verify_eci(eci)
def test_external_lib(): eci = ExternalCompilationInfo() c_source = """ int f(int a, int b) { return (a + b); } """ if platform.name == 'msvc': c_source = '__declspec(dllexport) ' + c_source libname = 'libc_lib' else: libname = 'c_lib' tmpdir = udir.join('external_lib').ensure(dir=1) c_file = tmpdir.join('libc_lib.c') c_file.write(c_source) l = platform.compile([c_file], eci, standalone=False) eci = ExternalCompilationInfo( libraries = [libname], library_dirs = [str(tmpdir)] ) rffi_platform.verify_eci(eci)
def test_external_lib(): eci = ExternalCompilationInfo(include_dirs = [cdir]) c_source = """ #include "src/precommondefs.h" RPY_EXPORTED int f(int a, int b) { return (a + b); } """ if platform.name == 'msvc': libname = 'libc_lib' else: libname = 'c_lib' tmpdir = udir.join('external_lib').ensure(dir=1) c_file = tmpdir.join('libc_lib.c') c_file.write(c_source) l = platform.compile([c_file], eci, standalone=False) eci = ExternalCompilationInfo( libraries = [libname], library_dirs = [str(tmpdir)] ) rffi_platform.verify_eci(eci)
from rpython.rtyper.lltypesystem import rffi, lltype from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rtyper.tool import rffi_platform as platform from rpython.rtyper.extfunc import register_external class LocaleError(Exception): def __init__(self, message): self.message = message HAVE_LANGINFO = sys.platform != 'win32' HAVE_LIBINTL = sys.platform != 'win32' libraries = [] if HAVE_LIBINTL: try: platform.verify_eci(ExternalCompilationInfo(includes=['libintl.h'], libraries=['intl'])) libraries.append('intl') except platform.CompilationError: try: platform.verify_eci(ExternalCompilationInfo(includes=['libintl.h'])) except platform.CompilationError: HAVE_LIBINTL = False class CConfig: includes = ['locale.h', 'limits.h', 'ctype.h', 'wchar.h'] libraries = libraries if HAVE_LANGINFO: includes += ['langinfo.h'] if HAVE_LIBINTL: includes += ['libintl.h']
def test_verify_eci(): eci = ExternalCompilationInfo() rffi_platform.verify_eci(eci) eci = ExternalCompilationInfo(libraries=['some_name_that_doesnt_exist_']) py.test.raises(rffi_platform.CompilationError, rffi_platform.verify_eci, eci)
"""], ) if DYNAMIC_VMPROF: eci_kwds['libraries'] += ['vmprof'] eci_kwds['link_extra'] = ['-Wl,-rpath,%s' % SRC, '-L%s' % SRC] else: eci_kwds['separate_module_files'] += [SRC.join('vmprof.c')] eci = ExternalCompilationInfo(**eci_kwds) check_eci = eci.merge(ExternalCompilationInfo(separate_module_files=[ SRC.join('fake_pypy_api.c')])) platform.verify_eci(check_eci) pypy_execute_frame_trampoline = rffi.llexternal( "pypy_execute_frame_trampoline", [llmemory.GCREF, llmemory.GCREF, llmemory.GCREF, lltype.Signed], llmemory.GCREF, compilation_info=eci, _nowrapper=True, sandboxsafe=True, random_effects_on_gcobjs=True) pypy_vmprof_init = rffi.llexternal("pypy_vmprof_init", [], rffi.INT, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [rffi.INT, rffi.LONG, rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT, compilation_info=eci,
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',
from rpython.rlib.objectmodel import we_are_translated from rpython.rlib import rposix from rpython.jit.backend.x86 import profagent class OProfileError(Exception): def __init__(self, errno, where): self.errno = errno self.where = where eci = ExternalCompilationInfo(includes=['stdint.h', 'opagent.h'], library_dirs=['/usr/local/lib/oprofile/'], libraries=['bfd', 'opagent']) try: rffi_platform.verify_eci(eci) except rffi_platform.CompilationError: OPROFILE_AVAILABLE = False else: OPROFILE_AVAILABLE = True AGENT = rffi.VOIDP uint64_t = rffi.ULONGLONG op_open_agent = rffi.llexternal("op_open_agent", [], AGENT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) op_close_agent = rffi.llexternal("op_close_agent", [AGENT], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) # arguments are:
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)
], ) if DYNAMIC_VMPROF: eci_kwds['libraries'] += ['vmprof'] eci_kwds['link_extra'] = ['-Wl,-rpath,%s' % SRC, '-L%s' % SRC] else: eci_kwds['separate_module_files'] += [SRC.join('vmprof.c')] eci = ExternalCompilationInfo(**eci_kwds) check_eci = eci.merge( ExternalCompilationInfo( separate_module_files=[SRC.join('fake_pypy_api.c')])) platform.verify_eci(check_eci) pypy_execute_frame_trampoline = rffi.llexternal( "pypy_execute_frame_trampoline", [llmemory.GCREF, llmemory.GCREF, llmemory.GCREF, lltype.Signed], llmemory.GCREF, compilation_info=eci, _nowrapper=True, sandboxsafe=True, random_effects_on_gcobjs=True) pypy_vmprof_init = rffi.llexternal("pypy_vmprof_init", [], rffi.INT, compilation_info=eci) vmprof_enable = rffi.llexternal( "vmprof_enable", [rffi.INT, rffi.LONG, rffi.INT, rffi.CCHARP, rffi.INT],
""" Support for valgrind: tell it when we patch code in-place. """ from rpython.rtyper.tool import rffi_platform from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rlib.objectmodel import we_are_translated eci = ExternalCompilationInfo(includes = ['valgrind/valgrind.h']) try: rffi_platform.verify_eci(eci) except rffi_platform.CompilationError: VALGRIND_DISCARD_TRANSLATIONS = None else: VALGRIND_DISCARD_TRANSLATIONS = rffi.llexternal( "VALGRIND_DISCARD_TRANSLATIONS", [llmemory.Address, lltype.Signed], lltype.Void, compilation_info=eci, _nowrapper=True, sandboxsafe=True) # ____________________________________________________________ def discard_translations(data, size): if we_are_translated() and VALGRIND_DISCARD_TRANSLATIONS is not None: VALGRIND_DISCARD_TRANSLATIONS(llmemory.cast_int_to_adr(data), size)
from rpython.rtyper.extfunc import register_external class LocaleError(Exception): def __init__(self, message): self.message = message HAVE_LANGINFO = sys.platform != 'win32' HAVE_LIBINTL = sys.platform != 'win32' libraries = [] if HAVE_LIBINTL: try: platform.verify_eci( ExternalCompilationInfo(includes=['libintl.h'], libraries=['intl'])) libraries.append('intl') except platform.CompilationError: try: platform.verify_eci( ExternalCompilationInfo(includes=['libintl.h'])) except platform.CompilationError: HAVE_LIBINTL = False class CConfig: includes = ['locale.h', 'limits.h', 'ctype.h', 'wchar.h'] libraries = libraries if HAVE_LANGINFO: