Esempio n. 1
0
 def test_dlsym(self):
     s = rffi.str2charp(get_libc_name())
     lib = dlopen(s)
     rffi.free_charp(s)
     handle = rffi.cast(lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed)), dlsym(lib, "abs"))
     assert 1 == handle(1)
     assert 1 == handle(-1)
Esempio n. 2
0
 def test__ffi_call_releases_gil(self):
     from rpython.rlib.clibffi import get_libc_name
     def main(libc_name, n):
         import time
         import os
         from threading import Thread
         #
         if os.name == 'nt':
             from _rawffi.alt import WinDLL, types
             libc = WinDLL('Kernel32.dll')
             sleep = libc.getfunc('Sleep', [types.uint], types.uint)
             delays = [0]*n + [1000]
         else:
             from _rawffi.alt import CDLL, types
             libc = CDLL(libc_name)
             sleep = libc.getfunc('sleep', [types.uint], types.uint)
             delays = [0]*n + [1]
         #
         def loop_of_sleeps(i, delays):
             for delay in delays:
                 sleep(delay)    # ID: sleep
         #
         threads = [Thread(target=loop_of_sleeps, args=[i, delays]) for i in range(5)]
         start = time.time()
         for i, thread in enumerate(threads):
             thread.start()
         for thread in threads:
             thread.join()
         end = time.time()
         return end - start
     log = self.run(main, [get_libc_name(), 200], threshold=150,
                    import_site=True)
     assert 1 <= log.result <= 1.5 # at most 0.5 seconds of overhead
     loops = log.loops_by_id('sleep')
     assert len(loops) == 1 # make sure that we actually JITted the loop
Esempio n. 3
0
 def test_dlopen(self):
     s = rffi.str2charp("xxxxxxxxxxxx")
     py.test.raises(DLOpenError, "dlopen(s)")
     rffi.free_charp(s)
     #
     s = rffi.str2charp(get_libc_name())
     assert dlopen(s)
     rffi.free_charp(s)
Esempio n. 4
0
 def setup_class(cls):
     space = cls.space
     cls.w_iswin32 = space.wrap(sys.platform == 'win32')
     cls.w_libfoo_name = space.wrap(cls.prepare_c_example())
     cls.w_libc_name = space.wrap(get_libc_name())
     libm_name = get_libm_name(sys.platform)
     cls.w_libm_name = space.wrap(libm_name)
     libm = CDLL(libm_name)
     pow = libm.getpointer('pow', [], types.void)
     pow_addr = rffi.cast(rffi.LONG, pow.funcsym)
     cls._libm = libm     # otherwise it gets unloaded - argh!
     cls.w_pow_addr = space.wrap(pow_addr)
Esempio n. 5
0
 def setup_class(cls):
     space = cls.space
     from rpython.rlib.clibffi import get_libc_name
     cls.w_lib_name = space.wrap(cls.prepare_c_example())
     cls.w_libc_name = space.wrap(get_libc_name())
     if sys.platform == 'win32':
         cls.w_iswin32 = space.wrap(True)
         cls.w_libm_name = space.wrap('msvcrt')
     else:
         cls.w_iswin32 = space.wrap(False)
         cls.w_libm_name = space.wrap('libm.so')
         if sys.platform == "darwin":
             cls.w_libm_name = space.wrap('libm.dylib')
     cls.w_platform = space.wrap(platform.name)
     cls.w_sizes_and_alignments = space.wrap(dict(
         [(k, (v.c_size, v.c_alignment)) for k,v in TYPEMAP.iteritems()]))
     cls.w_float_typemap = space.wrap(TYPEMAP_FLOAT_LETTERS)
Esempio n. 6
0
        def f():
            libc = CDLL(get_libc_name())
            qsort = libc.getpointer('qsort', [ffi_type_pointer, ffi_size_t,
                                              ffi_size_t, ffi_type_pointer],
                                    ffi_type_void)

            ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
                                  ffi_type_sint, callback)

            TP = rffi.CArray(lltype.Signed)
            to_sort = lltype.malloc(TP, 4, flavor='raw')
            to_sort[0] = 4
            to_sort[1] = 3
            to_sort[2] = 1
            to_sort[3] = 2
            qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
            qsort.push_arg(rffi.cast(rffi.SIZE_T, 4))
            qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(lltype.Signed)))
            qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
            qsort.call(lltype.Void)
            result = [to_sort[i] for i in range(4)] == [1, 2, 3, 4]
            lltype.free(to_sort, flavor='raw')
            keepalive_until_here(ptr)
            return int(result)
Esempio n. 7
0
def get_libc(space):
    try:
        return space.wrap(W_CDLL(space, get_libc_name(), -1))
    except OSError, e:
        raise wrap_oserror(space, e)
Esempio n. 8
0
 def setup_class(cls):
     from rpython.rlib.clibffi import get_libc_name
     if cls.runappdirect:
         cls.libc = get_libc_name()
     else:
         cls.w_libc = cls.space.wrap(get_libc_name())
Esempio n. 9
0
 def setup_class(cls):
     from rpython.rlib.clibffi import get_libc_name
     cls.w_libc = cls.space.wrap(get_libc_name())
Esempio n. 10
0
from rpython.translator.platform import platform
import pixie.vm.rt as rt
from pixie.vm.string import String
from pixie.vm.code import as_var
from rpython.rlib.clibffi import get_libc_name
import os


as_var("pixie.platform", "os")(String(unicode(os.name)))
as_var("pixie.platform", "name")(String(unicode(platform.name)))
as_var("pixie.platform", "so-ext")(String(unicode(platform.so_ext)))
as_var("pixie.platform", "lib-c-name")(String(unicode(get_libc_name())))
Esempio n. 11
0
def get_libc(space):
    return space.wrap(W_CDLL(space, get_libc_name(), -1))
Esempio n. 12
0
def call(self, arguments):
    assert len(arguments) == 0
    return [data.ByteString(ffi.get_libc_name())]
Esempio n. 13
0
 def setup_class(cls):
     from rpython.rlib.clibffi import get_libc_name
     cls.w_libc = cls.space.wrap(get_libc_name())
     state = cls.space.fromcache(RefcountState)
     state.non_heaptypes_w[:] = []
Esempio n. 14
0
def get_libc(space):
    return W_CDLL(space, get_libc_name(), -1, 0)
Esempio n. 15
0
 def setup_class(cls):
     from rpython.rlib.clibffi import get_libc_name
     if cls.runappdirect:
         cls.libc = get_libc_name()
     else:
         cls.w_libc = cls.space.wrap(get_libc_name())