示例#1
0
文件: test_libffi.py 项目: ieure/pypy
    def call(self, funcspec, args, RESULT, init_result=0, is_struct=False):
        """
        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, r_singlefloat):
                chain.arg_singlefloat(float(arg))
            elif IS_32_BIT and isinstance(arg, r_longlong):
                chain.arg_longlong(longlong2float(arg))
            elif IS_32_BIT and isinstance(arg, r_ulonglong):
                arg = rffi.cast(rffi.LONGLONG, arg)
                chain.arg_longlong(longlong2float(arg))
            elif 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)