• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python lltype.functionptr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.functionptr函数的典型用法代码示例。如果您正苦于以下问题:Python functionptr函数的具体用法?Python functionptr怎么用?Python functionptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了functionptr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: g

 def g(vobj):
     vobj = lltype.normalizeptr(vobj)
     LLV = lltype.typeOf(vobj).TO
     ACCESS = LLV.ACCESS
     access = lltype.malloc(ACCESS, immortal=True)
     fp = lltype.functionptr(ACCESS.parent.get_inst_v0.TO, 'getv0',
                             _callable=getv0)        
     access.parent.get_inst_v0= fp
                                  
     access.get_inst_v1 = lltype.functionptr(ACCESS.get_inst_v1.TO,
                                            'getv1', _callable=getv1)
     vobj.super.vable_access = access.parent
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:12,代码来源:test_rvirtualizable.py


示例2: test_caching_dynamic_deallocator

def test_caching_dynamic_deallocator():
    S = lltype.GcStruct("S", ('x', lltype.Signed))
    S1 = lltype.GcStruct("S1", ('s', S), ('y', lltype.Signed))
    T = lltype.GcStruct("T", ('x', lltype.Signed))
    def f_S(s):
        s.x = 1
    def f_S1(s1):
        s1.s.x = 1
        s1.y = 2
    def f_T(s):
        s.x = 1
    def type_info_S(p):
        return lltype.getRuntimeTypeInfo(S)
    def type_info_T(p):
        return lltype.getRuntimeTypeInfo(T)
    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
                            "type_info_S",
                            _callable=type_info_S)
    dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Void),
                            "destructor_funcptr",
                            _callable=f_S)
    pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
    dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Void),
                            "destructor_funcptr",
                            _callable=f_S1)
    pinf = lltype.attachRuntimeTypeInfo(S1, qp, destrptr=dp)
    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(T)],
                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
                            "type_info_S",
                            _callable=type_info_T)
    dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(T)],
                                            lltype.Void),
                            "destructor_funcptr",
                            _callable=f_T)
    pinf = lltype.attachRuntimeTypeInfo(T, qp, destrptr=dp)
    def f():
        pass
    t = TranslationContext()
    t.buildannotator().build_types(f, [])
    t.buildrtyper().specialize()
    transformer = RefcountingGCTransformer(t)
    p_S = transformer.dynamic_deallocation_funcptr_for_type(S)
    p_S1 = transformer.dynamic_deallocation_funcptr_for_type(S1)
    p_T = transformer.dynamic_deallocation_funcptr_for_type(T)
    assert p_S is not p_T
    assert p_S is p_S1
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:49,代码来源:test_refcounting.py


示例3: newgraph

def newgraph(gv_FUNCTYPE, name):
    FUNCTYPE = from_opaque_object(gv_FUNCTYPE).value
    # 'name' is just a way to track things
    if not isinstance(name, str):
        name = LLSupport.from_rstr(name)
    inputargs = []
    erasedinputargs = []
    for ARG in FUNCTYPE.ARGS:
        v = flowmodel.Variable()
        v.concretetype = ARG
        inputargs.append(v)
        v = flowmodel.Variable()
        v.concretetype = lltype.erasedType(ARG)
        erasedinputargs.append(v)
    startblock = flowmodel.Block(inputargs)
    # insert an exploding operation here which is removed by
    # builder.end() to ensure that builder.end() is actually called.
    startblock.operations.append(
        flowmodel.SpaceOperation("debug_assert",
                                 [flowmodel.Constant(False, lltype.Bool),
                                  flowmodel.Constant("you didn't call builder.end()?",
                                                     lltype.Void)],
                                 varoftype(lltype.Void)))
    return_var = flowmodel.Variable()
    return_var.concretetype = FUNCTYPE.RESULT
    graph = flowmodel.FunctionGraph(name, startblock, return_var)
    v1 = flowmodel.Variable()
    v1.concretetype = lltype.erasedType(FUNCTYPE.RESULT)
    graph.prereturnblock = flowmodel.Block([v1])
    casting_link(graph.prereturnblock, [v1], graph.returnblock)
    substartblock = flowmodel.Block(erasedinputargs)
    casting_link(graph.startblock, inputargs, substartblock)
    fptr = lltype.functionptr(FUNCTYPE, name,
                              graph=graph)
    return genconst(fptr)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:35,代码来源:llimpl.py


示例4: test_assemble_cast_consts

def test_assemble_cast_consts():
    ssarepr = SSARepr("test")
    S = lltype.GcStruct('S')
    s = lltype.malloc(S)
    F = lltype.FuncType([], lltype.Signed)
    f = lltype.functionptr(F, 'f')
    ssarepr.insns = [
        ('int_return', Constant('X', lltype.Char)),
        ('int_return', Constant(unichr(0x1234), lltype.UniChar)),
        ('int_return', Constant(f, lltype.Ptr(F))),
        ('ref_return', Constant(s, lltype.Ptr(S))),
        ]
    assembler = Assembler()
    jitcode = assembler.assemble(ssarepr)
    assert jitcode.code == ("\x00\x58"
                            "\x01\xFF"
                            "\x01\xFE"
                            "\x02\xFF")
    assert assembler.insns == {'int_return/c': 0,
                               'int_return/i': 1,
                               'ref_return/r': 2}
    f_int = heaptracker.adr2int(llmemory.cast_ptr_to_adr(f))
    assert jitcode.constants_i == [0x1234, f_int]
    s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
    assert jitcode.constants_r == [s_gcref]
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_assembler.py


示例5: test_llexternal

    def test_llexternal(self):
        from pypy.rpython.lltypesystem.rffi import llexternal
        from pypy.rpython.lltypesystem import lltype
        z = llexternal('z', [lltype.Signed], lltype.Signed)
        def f(x):
            return z(x)
        t, ra = self.translate(f, [int])
        fgraph = graphof(t, f)
        backend_optimizations(t)
        assert fgraph.startblock.operations[0].opname == 'direct_call'

        result = ra.can_raise(fgraph.startblock.operations[0])
        assert not result

        z = lltype.functionptr(lltype.FuncType([lltype.Signed], lltype.Signed),
                               'foobar')
        def g(x):
            return z(x)
        t, ra = self.translate(g, [int])
        ggraph = graphof(t, g)

        assert ggraph.startblock.operations[0].opname == 'direct_call'

        result = ra.can_raise(ggraph.startblock.operations[0])
        assert result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_canraise.py


示例6: test_deallocator_with_destructor

def test_deallocator_with_destructor():
    S = lltype.GcStruct("S", ('x', lltype.Signed))
    def f(s):
        s.x = 1
    def type_info_S(p):
        return lltype.getRuntimeTypeInfo(S)
    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
                            "type_info_S",
                            _callable=type_info_S)
    dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Void),
                            "destructor_funcptr",
                            _callable=f)
    pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
    graph, t = make_deallocator(S)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:16,代码来源:test_refcounting.py


示例7: test_get_accessor

def test_get_accessor():

    G = lltype.FuncType([rclass.OBJECTPTR], lltype.Void)

    witness = []
    
    def getv(vinst):
        value = vinst.inst_v
        witness.append(value)
        return value

    def g(vobj):
        vobj = lltype.normalizeptr(vobj)
        LLV = lltype.typeOf(vobj).TO
        ACCESS = LLV.vable_access.TO
        access = lltype.malloc(ACCESS, immortal=True)
        access.get_inst_v = lltype.functionptr(ACCESS.get_inst_v.TO,
                                               'getv', _callable=getv)
        vobj.vable_access = access
        
    gptr = lltype.functionptr(G, 'g', _callable=g)
    
    def f(v):
        vinst = V(v)
        vobj = cast_instance_to_base_ptr(vinst)
        gptr(vobj)
        x = vinst.v
        return x
    res = interpret(f, [42])
    assert res == 42

    assert witness == [42]
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:32,代码来源:test_rvirtualizable.py


示例8: test_set_accessor

def test_set_accessor():

    G = lltype.FuncType([rclass.OBJECTPTR], lltype.Void)

    witness = []
    
    def setv(vinst, val):
        witness.append(val)
        vinst.inst_v = val

    def g(vobj):
        vobj = lltype.normalizeptr(vobj)
        LLV = lltype.typeOf(vobj).TO
        ACCESS = LLV.vable_access.TO
        access = lltype.malloc(ACCESS, immortal=True)
        access.set_inst_v = lltype.functionptr(ACCESS.set_inst_v.TO,
                                               'setv', _callable=setv)
        vobj.vable_access = access
        
    gptr = lltype.functionptr(G, 'g', _callable=g)
    
    def f(v):
        vinst = V(v)
        vobj = cast_instance_to_base_ptr(vinst)
        gptr(vobj)
        vinst.v = 33
    res = interpret(f, [42])

    assert witness == [33]
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:29,代码来源:test_rvirtualizable.py


示例9: test_boehm_finalizer_nomix___del___and_pyobj

def test_boehm_finalizer_nomix___del___and_pyobj():
    S = lltype.GcStruct("S", ('x', lltype.Signed), ('y', lltype.Ptr(lltype.PyObject)))
    def f(s):
        s.x = 1
    def type_info_S(p):
        return lltype.getRuntimeTypeInfo(S)
    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
                            "type_info_S",
                            _callable=type_info_S)
    dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Void),
                            "destructor_funcptr",
                            _callable=f)
    pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
    py.test.raises(Exception, "make_boehm_finalizer(S)")
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:16,代码来源:test_boehm.py


示例10: test_decode_builtin_call_method

def test_decode_builtin_call_method():
    A = lltype.GcArray(lltype.Signed)
    def myfoobar(a, i, marker, c):
        assert marker == 'mymarker'
        return a[i] * ord(c)
    myfoobar.oopspec = 'spam.foobar(a, 2, c, i)'
    TYPE = lltype.FuncType([lltype.Ptr(A), lltype.Signed,
                            lltype.Void, lltype.Char],
                           lltype.Signed)
    fnobj = lltype.functionptr(TYPE, 'foobar', _callable=myfoobar)
    vi = Variable('i')
    vi.concretetype = lltype.Signed
    vc = Variable('c')
    vc.concretetype = lltype.Char
    v_result = Variable('result')
    v_result.concretetype = lltype.Signed
    myarray = lltype.malloc(A, 10)
    myarray[5] = 42
    op = SpaceOperation('direct_call', [newconst(fnobj),
                                        newconst(myarray),
                                        vi,
                                        voidconst('mymarker'),
                                        vc],
                        v_result)
    oopspec, opargs = decode_builtin_call(op)
    assert oopspec == 'spam.foobar'
    assert opargs == [newconst(myarray), newconst(2), vc, vi]
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:test_support.py


示例11: specialize_call

 def specialize_call(self, hop):
     FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r],
                                hop.r_result.lowleveltype)
     args_v = hop.inputargs(*hop.args_r)
     funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
                                  _callable=func, _debugexc=True)
     cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
     return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:llimpl.py


示例12: genexternalcall

 def genexternalcall(self, fnname, args_v, resulttype=None, **flags):
     if isinstance(resulttype, Repr):
         resulttype = resulttype.lowleveltype
     argtypes = [v.concretetype for v in args_v]
     FUNCTYPE = FuncType(argtypes, resulttype or Void)
     f = functionptr(FUNCTYPE, fnname, **flags)
     cf = inputconst(typeOf(f), f)
     return self.genop('direct_call', [cf]+list(args_v), resulttype)
开发者ID:ieure,项目名称:pypy,代码行数:8,代码来源:rtyper.py


示例13: get_direct_call_op

def get_direct_call_op(argtypes, restype):
    FUNC = lltype.FuncType(argtypes, restype)
    fnptr = lltype.functionptr(FUNC, "g")    # no graph
    c_fnptr = const(fnptr)
    vars = [varoftype(TYPE) for TYPE in argtypes]
    v_result = varoftype(restype)
    op = SpaceOperation('direct_call', [c_fnptr] + vars, v_result)
    return op
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:test_jtransform.py


示例14: test_boehm_finalizer___del__

def test_boehm_finalizer___del__():
    S = lltype.GcStruct("S", ('x', lltype.Signed))
    def f(s):
        s.x = 1
    def type_info_S(p):
        return lltype.getRuntimeTypeInfo(S)
    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
                            "type_info_S",
                            _callable=type_info_S)
    dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                            lltype.Void),
                            "destructor_funcptr",
                            _callable=f)
    pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
    f, t = make_boehm_finalizer(S)
    assert f is not None
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:test_boehm.py


示例15: test_half_exceptiontransformed_graphs

def test_half_exceptiontransformed_graphs():
    from pypy.translator import exceptiontransform

    def f1(x):
        if x < 0:
            raise ValueError
        return 754

    def g1(x):
        try:
            return f1(x)
        except ValueError:
            return 5

    def f2(x):
        if x < 0:
            raise ValueError
        return 21

    def g2(x):
        try:
            return f2(x)
        except ValueError:
            return 6

    f3 = lltype.functionptr(lltype.FuncType([lltype.Signed], lltype.Signed), "f3", _callable=f1)

    def g3(x):
        try:
            return f3(x)
        except ValueError:
            return 7

    def f(flag, x):
        if flag == 1:
            return g1(x)
        elif flag == 2:
            return g2(x)
        else:
            return g3(x)

    t = TranslationContext()
    t.buildannotator().build_types(f, [int, int])
    t.buildrtyper().specialize()
    etrafo = exceptiontransform.ExceptionTransformer(t)
    etrafo.create_exception_handling(graphof(t, f1))
    etrafo.create_exception_handling(graphof(t, g2))
    etrafo.create_exception_handling(graphof(t, g3))
    graph = graphof(t, f)
    interp = LLInterpreter(t.rtyper)
    res = interp.eval_graph(graph, [1, -64])
    assert res == 5
    res = interp.eval_graph(graph, [2, -897])
    assert res == 6
    res = interp.eval_graph(graph, [3, -9831])
    assert res == 7
开发者ID:are-prabhu,项目名称:pypy,代码行数:56,代码来源:test_llinterp.py


示例16: test_graphs_from_direct_call

def test_graphs_from_direct_call():
    cc = CallControl()
    F = lltype.FuncType([], lltype.Signed)
    f = lltype.functionptr(F, 'f', graph='fgraph')
    v = varoftype(lltype.Signed)
    op = SpaceOperation('direct_call', [Constant(f, lltype.Ptr(F))], v)
    #
    lst = cc.graphs_from(op, {}.__contains__)
    assert lst is None     # residual call
    #
    lst = cc.graphs_from(op, {'fgraph': True}.__contains__)
    assert lst == ['fgraph']     # normal call
开发者ID:ieure,项目名称:pypy,代码行数:12,代码来源:test_call.py


示例17: llexternal

def llexternal(name, args, result, _callable=None, sources=[], includes=[],
               libraries=[], include_dirs=[]):
    ext_type = lltype.FuncType(args, result)
    funcptr = lltype.functionptr(ext_type, name, external='C',
                                 sources=tuple(sources),
                                 includes=tuple(includes),
                                 libraries=tuple(libraries),
                                 include_dirs=tuple(include_dirs),
                                 _callable=_callable)
    if _callable is None:
        from pypy.rpython.lltypesystem import ll2ctypes
        ll2ctypes.make_callable_via_ctypes(funcptr)
    return funcptr
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:13,代码来源:rffi.py


示例18: test_c_callback_with_void_arg_2

 def test_c_callback_with_void_arg_2(self):
     ftest = []
     def f(x):
         ftest.append(x)
     F = lltype.FuncType([lltype.Void], lltype.Void)
     fn = lltype.functionptr(F, 'askjh', _callable=f, _void0=-5)
     fn(-5)
     assert ftest == [-5]
     fn2 = lltype2ctypes(fn)
     fn2()
     assert ftest == [-5, -5]
     fn3 = ctypes2lltype(lltype.Ptr(F), fn2)
     fn3(-5)
     assert ftest == [-5, -5, -5]
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:test_ll2ctypes.py


示例19: specialize_call

 def specialize_call(self, hop):
     ARGS = [r.lowleveltype for r in hop.args_r]
     RESULT = hop.r_result.lowleveltype
     if hop.rtyper.type_system.name == 'lltypesystem':
         FUNCTYPE = lltype.FuncType(ARGS, RESULT)
         funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
                                      _callable=func, _debugexc=True)
         cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
     else:
         FUNCTYPE = ootype.StaticMethod(ARGS, RESULT)
         sm = ootype._static_meth(FUNCTYPE, _name=func.__name__, _callable=func)
         cfunc = hop.inputconst(FUNCTYPE, sm)
     args_v = hop.inputargs(*hop.args_r)
     return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:14,代码来源:llimpl.py


示例20: ctypes2lltype

def ctypes2lltype(T, cobj):
    """Convert the ctypes object 'cobj' to its lltype equivalent.
    'T' is the expected lltype type.
    """
    if isinstance(T, lltype.Ptr):
        if not cobj:   # NULL pointer
            return lltype.nullptr(T.TO)
        if isinstance(T.TO, lltype.Struct):
            if T.TO._arrayfld is not None:
                raise NotImplementedError("XXX var-sized structs")
            container = lltype._struct(T.TO)
            struct_use_ctypes_storage(container, cobj.contents)
        elif isinstance(T.TO, lltype.Array):
            if T.TO._hints.get('nolength', False):
                container = _array_of_unknown_length(T.TO)
                container._storage = cobj.contents
            else:
                raise NotImplementedError("array with an explicit length")
        elif isinstance(T.TO, lltype.FuncType):
            _callable = get_ctypes_trampoline(T.TO, cobj)
            return lltype.functionptr(T.TO, getattr(cobj, '__name__', '?'),
                                      _callable=_callable)
        elif isinstance(T.TO, lltype.OpaqueType):
            container = lltype._opaque(T.TO)
        else:
            raise NotImplementedError(T)
        llobj = lltype._ptr(T, container, solid=True)
    elif T is lltype.Char:
        llobj = chr(cobj)
    elif T is lltype.UniChar:
        llobj = unichr(cobj)
    elif T is lltype.Signed:
        llobj = cobj
    elif T is lltype.SingleFloat:
        if isinstance(cobj, ctypes.c_float):
            cobj = cobj.value
        llobj = r_singlefloat(cobj)
    else:
        from pypy.rpython.lltypesystem import rffi
        try:
            inttype = rffi.platform.numbertype_to_rclass[T]
        except KeyError:
            llobj = cobj
        else:
            llobj = inttype(cobj)

    assert lltype.typeOf(llobj) == T
    return llobj
开发者ID:antoine1fr,项目名称:pygirl,代码行数:48,代码来源:ll2ctypes.py



注:本文中的pypy.rpython.lltypesystem.lltype.functionptr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python lltype.malloc函数代码示例发布时间:2022-05-27
下一篇:
Python lltype.free函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap