Ejemplo n.º 1
0
 def test_windll(self):
     if os.name != 'nt':
         py.test.skip('Run only on windows')
     from rpython.rlib.libffi import WinDLL
     dll = WinDLL('Kernel32.dll')
     sleep = dll.getpointer('Sleep',[types.uint], types.void)
     chain = ArgChain()
     chain.arg(10)
     sleep.call(chain, lltype.Void, is_struct=False)
Ejemplo n.º 2
0
 def test_windll(self):
     if os.name != 'nt':
         py.test.skip('Run only on windows')
     from rpython.rlib.libffi import WinDLL
     dll = WinDLL('Kernel32.dll')
     sleep = dll.getpointer('Sleep', [types.uint], types.void)
     chain = ArgChain()
     chain.arg(10)
     sleep.call(chain, lltype.Void, is_struct=False)
Ejemplo n.º 3
0
 def libffi_stuff(i, j):
     lib = CDLL(libm_name)
     func = lib.getpointer("fabs", [types.double], types.double)
     res = 0.0
     x = float(j)
     while i > 0:
         jitdriver2.jit_merge_point(i=i, res=res, func=func, x=x)
         promote(func)
         argchain = ArgChain()
         argchain.arg(x)
         res = func.call(argchain, rffi.DOUBLE)
         i -= 1
     return res
Ejemplo n.º 4
0
 def libffi_stuff(i, j):
     lib = CDLL(libm_name)
     func = lib.getpointer('fabs', [types.double], types.double)
     res = 0.0
     x = float(j)
     v2 = Virt2(i)
     while v2.i > 0:
         jitdriver2.jit_merge_point(v2=v2, res=res, func=func, x=x)
         promote(func)
         argchain = ArgChain()
         argchain.arg(x)
         res = func.call(argchain, rffi.DOUBLE)
         v2.i -= 1
     return res
Ejemplo n.º 5
0
 def test_argchain(self):
     chain = ArgChain()
     assert chain.numargs == 0
     chain2 = chain.arg(42)
     assert chain2 is chain
     assert chain.numargs == 1
     intarg = chain.first
     assert chain.last is intarg
     assert intarg.intval == 42
     chain.arg(123.45)
     assert chain.numargs == 2
     assert chain.first is intarg
     assert intarg.next is chain.last
     floatarg = intarg.next
     assert floatarg.floatval == 123.45
Ejemplo n.º 6
0
 def test_argchain(self):
     chain = ArgChain()
     assert chain.numargs == 0
     chain2 = chain.arg(42)
     assert chain2 is chain
     assert chain.numargs == 1
     intarg = chain.first
     assert chain.last is intarg
     assert intarg.intval == 42
     chain.arg(123.45)
     assert chain.numargs == 2
     assert chain.first is intarg
     assert intarg.next is chain.last
     floatarg = intarg.next
     assert floatarg.floatval == 123.45
Ejemplo n.º 7
0
    def call(self, funcspec, args, RESULT, is_struct=False, jitif=[]):
        """
        Call the specified function after constructing and ArgChain with the
        arguments in ``args``.

        The function is specified with ``funcspec``, which is a tuple of the
        form (lib, name, argtypes, restype).

        This method is overridden by metainterp/test/test_fficall.py in
        order to do the call in a loop and JIT it. The optional arguments are
        used only by that overridden method.

        """
        lib, name, argtypes, restype = funcspec
        func = lib.getpointer(name, argtypes, restype)
        chain = ArgChain()
        for arg in args:
            if isinstance(arg, tuple):
                methname, arg = arg
                meth = getattr(chain, methname)
                meth(arg)
            else:
                chain.arg(arg)
        return func.call(chain, RESULT, is_struct=is_struct)
Ejemplo n.º 8
0
    def call(self, funcspec, args, RESULT, is_struct=False, jitif=[]):
        """
        Call the specified function after constructing and ArgChain with the
        arguments in ``args``.

        The function is specified with ``funcspec``, which is a tuple of the
        form (lib, name, argtypes, restype).

        This method is overridden by metainterp/test/test_fficall.py in
        order to do the call in a loop and JIT it. The optional arguments are
        used only by that overridden method.

        """
        lib, name, argtypes, restype = funcspec
        func = lib.getpointer(name, argtypes, restype)
        chain = ArgChain()
        for arg in args:
            if isinstance(arg, tuple):
                methname, arg = arg
                meth = getattr(chain, methname)
                meth(arg)
            else:
                chain.arg(arg)
        return func.call(chain, RESULT, is_struct=is_struct)