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

Python annlowlevel.llhelper函数代码示例

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

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



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

示例1: test_call_stubs

def test_call_stubs():
    c0 = GcCache(False)
    ARGS = [lltype.Char, lltype.Signed]
    RES = lltype.Char
    descr1 = get_call_descr(c0, ARGS, RES)
    def f(a, b):
        return 'c'

    call_stub = descr1.call_stub
    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)

    res = call_stub(rffi.cast(lltype.Signed, fnptr), [1, 2], None, None)
    assert res == ord('c')

    ARRAY = lltype.GcArray(lltype.Signed)
    ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
    RES = lltype.Float

    def f(a, b):
        return float(b[0]) + a

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = lltype.malloc(ARRAY, 3)
    opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
    a[0] = 1
    res = descr2.call_stub(rffi.cast(lltype.Signed, fnptr),
                           [], [opaquea], [longlong.getfloatstorage(3.5)])
    assert longlong.getrealfloat(res) == 4.5
开发者ID:ieure,项目名称:pypy,代码行数:29,代码来源:test_descr.py


示例2: chooser

 def chooser(x):
     s = lltype.malloc(STRUCT, flavor="raw")
     if x:
         s.bar = llhelper(FTPTR, a_f.make_func())
     else:
         s.bar = llhelper(FTPTR, a_g.make_func())
     return f(s)
开发者ID:ieure,项目名称:pypy,代码行数:7,代码来源:test_genc.py


示例3: h

 def h(x, y, z):
     s = malloc(S)
     s.x = x
     s.y = y
     fptr = llhelper(F, f)
     gptr = llhelper(G, g)
     assert typeOf(fptr) == F
     return fptr(s, z)+fptr(s, z*2)+gptr(s)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_llann.py


示例4: setup_buffer_buffer_procs

def setup_buffer_buffer_procs(space, pto):
    c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True)
    lltype.render_immortal(c_buf)
    c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype,
                                      str_segcount.api_func.get_wrapper(space))
    c_buf.c_bf_getreadbuffer = llhelper(buf_getreadbuffer.api_func.functype,
                                 buf_getreadbuffer.api_func.get_wrapper(space))
    pto.c_tp_as_buffer = c_buf
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:typeobject.py


示例5: get_on_leave_jitted_int

 def get_on_leave_jitted_int(self, save_exception,
                             default_to_memoryerror=False):
     if default_to_memoryerror:
         f = llhelper(self._ON_JIT_LEAVE_FUNC, self.on_leave_jitted_memoryerr)
     elif save_exception:
         f = llhelper(self._ON_JIT_LEAVE_FUNC, self.on_leave_jitted_save_exc)
     else:
         f = llhelper(self._ON_JIT_LEAVE_FUNC, self.on_leave_jitted_noexc)
     return rffi.cast(lltype.Signed, f)
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:9,代码来源:llmodel.py


示例6: type_attach

def type_attach(space, py_obj, w_type):
    """
    Fills a newly allocated PyTypeObject from an existing type.
    """
    from pypy.module.cpyext.object import PyObject_Del

    assert isinstance(w_type, W_TypeObject)

    pto = rffi.cast(PyTypeObjectPtr, py_obj)

    typedescr = get_typedescr(w_type.instancetypedef)

    # dealloc
    pto.c_tp_dealloc = typedescr.get_dealloc(space)
    # buffer protocol
    if space.is_w(w_type, space.w_str):
        setup_string_buffer_procs(space, pto)
    if space.is_w(w_type, space.gettypefor(Buffer)):
        setup_buffer_buffer_procs(space, pto)

    pto.c_tp_free = llhelper(PyObject_Del.api_func.functype,
            PyObject_Del.api_func.get_wrapper(space))
    pto.c_tp_alloc = llhelper(PyType_GenericAlloc.api_func.functype,
            PyType_GenericAlloc.api_func.get_wrapper(space))
    if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
        w_typename = space.getattr(w_type, space.wrap('__name__'))
        heaptype = rffi.cast(PyHeapTypeObject, pto)
        heaptype.c_ht_name = make_ref(space, w_typename)
        from pypy.module.cpyext.stringobject import PyString_AsString
        pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
    else:
        pto.c_tp_name = rffi.str2charp(w_type.getname(space))
    pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
    pto.c_tp_itemsize = 0
    # uninitialized fields:
    # c_tp_print, c_tp_getattr, c_tp_setattr
    # XXX implement
    # c_tp_compare and the following fields (see http://docs.python.org/c-api/typeobj.html )
    w_base = best_base(space, w_type.bases_w)
    pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))

    finish_type_1(space, pto)
    finish_type_2(space, pto, w_type)

    pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
    if pto.c_tp_base:
        if pto.c_tp_base.c_tp_basicsize > pto.c_tp_basicsize:
            pto.c_tp_basicsize = pto.c_tp_base.c_tp_basicsize

    # will be filled later on with the correct value
    # may not be 0
    if space.is_w(w_type, space.w_object):
        pto.c_tp_new = rffi.cast(newfunc, 1)
    update_all_slots(space, w_type, pto)
    pto.c_tp_flags |= Py_TPFLAGS_READY
    return pto
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:56,代码来源:typeobject.py


示例7: get_dealloc

 def get_dealloc(self, space):
     if tp_dealloc:
         return llhelper(
             tp_dealloc.api_func.functype,
             tp_dealloc.api_func.get_wrapper(space))
     else:
         from pypy.module.cpyext.typeobject import subtype_dealloc
         return llhelper(
             subtype_dealloc.api_func.functype,
             subtype_dealloc.api_func.get_wrapper(space))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:10,代码来源:pyobject.py


示例8: setup_string_buffer_procs

def setup_string_buffer_procs(space, pto):
    c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True)
    c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype,
                                      str_segcount.api_func.get_wrapper(space))
    c_buf.c_bf_getreadbuffer = llhelper(str_getreadbuffer.api_func.functype,
                                 str_getreadbuffer.api_func.get_wrapper(space))
    c_buf.c_bf_getcharbuffer = llhelper(str_getcharbuffer.api_func.functype,
                                 str_getcharbuffer.api_func.get_wrapper(space))
    pto.c_tp_as_buffer = c_buf
    pto.c_tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER
开发者ID:gorakhargosh,项目名称:pypy,代码行数:10,代码来源:typeobject.py


示例9: get_tp_function

    def get_tp_function(space, typedef):
        @cpython_api([], lltype.Signed, error=-1, external=False)
        def slot_tp_function(space):
            return typedef.value

        api_func = slot_tp_function.api_func
        return lambda: llhelper(api_func.functype, api_func.get_wrapper(space))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_translate.py


示例10: make_finalizer_funcptr_for_type

    def make_finalizer_funcptr_for_type(self, TYPE):
        from pypy.rpython.memory.gctransform.support import get_rtti, type_contains_pyobjs

        rtti = get_rtti(TYPE)
        if rtti is not None and hasattr(rtti._obj, "destructor_funcptr"):
            destrptr = rtti._obj.destructor_funcptr
            DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
            destrgraph = destrptr._obj.graph
        else:
            return None, False

        assert not type_contains_pyobjs(TYPE), "not implemented"
        t = self.llinterp.typer.annotator.translator
        light = not FinalizerAnalyzer(t).analyze_light_finalizer(destrgraph)

        def ll_finalizer(addr, dummy):
            assert dummy == llmemory.NULL
            try:
                v = llmemory.cast_adr_to_ptr(addr, DESTR_ARG)
                self.llinterp.eval_graph(destrgraph, [v], recursive=True)
            except llinterp.LLException:
                raise RuntimeError("a finalizer raised an exception, shouldn't happen")
            return llmemory.NULL

        return llhelper(gctypelayout.GCData.FINALIZER_OR_CT, ll_finalizer), light
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:gcwrapper.py


示例11: test_qsort

    def test_qsort(self):
        CMPFUNC = lltype.FuncType([rffi.VOIDP, rffi.VOIDP], rffi.INT)
        qsort = rffi.llexternal('qsort', [rffi.VOIDP,
                                          rffi.SIZE_T,
                                          rffi.SIZE_T,
                                          lltype.Ptr(CMPFUNC)],
                                lltype.Void)

        lst = [23, 43, 24, 324, 242, 34, 78, 5, 3, 10]
        A = lltype.Array(lltype.Signed, hints={'nolength': True})
        a = lltype.malloc(A, 10, flavor='raw')
        for i in range(10):
            a[i] = lst[i]

        SIGNEDPTR = lltype.Ptr(lltype.FixedSizeArray(lltype.Signed, 1))

        def my_compar(p1, p2):
            p1 = rffi.cast(SIGNEDPTR, p1)
            p2 = rffi.cast(SIGNEDPTR, p2)
            print 'my_compar:', p1[0], p2[0]
            return rffi.cast(rffi.INT, cmp(p1[0], p2[0]))

        qsort(rffi.cast(rffi.VOIDP, a),
              rffi.cast(rffi.SIZE_T, 10),
              rffi.cast(rffi.SIZE_T, llmemory.sizeof(lltype.Signed)),
              llhelper(lltype.Ptr(CMPFUNC), my_compar))

        for i in range(10):
            print a[i],
        print
        lst.sort()
        for i in range(10):
            assert a[i] == lst[i]
        lltype.free(a, flavor='raw')
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:35,代码来源:test_ll2ctypes.py


示例12: define_custom_trace

 def define_custom_trace(cls):
     from pypy.rpython.annlowlevel import llhelper
     from pypy.rpython.lltypesystem import llmemory
     #
     S = lltype.GcStruct('S', ('x', llmemory.Address), rtti=True)
     offset_of_x = llmemory.offsetof(S, 'x')
     def customtrace(obj, prev):
         if not prev:
             return obj + offset_of_x
         else:
             return llmemory.NULL
     CUSTOMTRACEFUNC = lltype.FuncType([llmemory.Address, llmemory.Address],
                                       llmemory.Address)
     customtraceptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), customtrace)
     lltype.attachRuntimeTypeInfo(S, customtraceptr=customtraceptr)
     #
     def setup():
         s = lltype.nullptr(S)
         for i in range(10000):
             t = lltype.malloc(S)
             t.x = llmemory.cast_ptr_to_adr(s)
             s = t
         return s
     def measure_length(s):
         res = 0
         while s:
             res += 1
             s = llmemory.cast_adr_to_ptr(s.x, lltype.Ptr(S))
         return res
     def f(n):
         s1 = setup()
         llop.gc__collect(lltype.Void)
         return measure_length(s1)
     return f
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:34,代码来源:test_newgc.py


示例13: get_shadowstackref

def get_shadowstackref(gctransformer):
    if hasattr(gctransformer, '_SHADOWSTACKREF'):
        return gctransformer._SHADOWSTACKREF

    SHADOWSTACKREFPTR = lltype.Ptr(lltype.GcForwardReference())
    SHADOWSTACKREF = lltype.GcStruct('ShadowStackRef',
                                     ('base', llmemory.Address),
                                     ('top', llmemory.Address),
                                     ('context', llmemory.Address),
                                     #('fullstack', lltype.Bool),
                                     rtti=True)
    SHADOWSTACKREFPTR.TO.become(SHADOWSTACKREF)

    gc = gctransformer.gcdata.gc
    root_iterator = get_root_iterator(gctransformer)

    def customtrace(obj, prev):
        obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
        if not prev:
            root_iterator.setcontext(obj.context)
            prev = obj.top
        return root_iterator.nextleft(gc, obj.base, prev)

    CUSTOMTRACEFUNC = lltype.FuncType([llmemory.Address, llmemory.Address],
                                      llmemory.Address)
    customtraceptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), customtrace)
    lltype.attachRuntimeTypeInfo(SHADOWSTACKREF, customtraceptr=customtraceptr)

    gctransformer._SHADOWSTACKREF = SHADOWSTACKREF
    return SHADOWSTACKREF
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:30,代码来源:shadowstack.py


示例14: _new_callback

def _new_callback():
    # Here, we just closed the stack.  Get the stack anchor, store
    # it in the gcrootfinder.suspstack.anchor, and create a new
    # stacklet with stacklet_new().  If this call fails, then we
    # are just returning NULL.
    _stack_just_closed()
    return _c.new(gcrootfinder.thrd, llhelper(_c.run_fn, _new_runfn),
                  llmemory.NULL)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:_stacklet_asmgcc.py


示例15: helper_func

 def helper_func(self, FUNCPTR, func):
     if not self.cpu.translate_support_code:
         return llhelper(FUNCPTR, func)
     FUNC = get_functype(FUNCPTR)
     args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
     s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
     graph = self.annhelper.getgraph(func, args_s, s_result)
     return self.annhelper.graph2delayed(graph, FUNC)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:warmspot.py


示例16: test_call_aligned_with_spilled_values

    def test_call_aligned_with_spilled_values(self):
        from pypy.rlib.libffi import types
        cpu = self.cpu
        if not cpu.supports_floats:
            py.test.skip('requires floats')


        def func(*args):
            return float(sum(args))

        F = lltype.Float
        I = lltype.Signed
        floats = [0.7, 5.8, 0.1, 0.3, 0.9, -2.34, -3.45, -4.56]
        ints = [7, 11, 23, 13, -42, 1111, 95, 1]
        for case in range(256):
            local_floats = list(floats)
            local_ints = list(ints)
            args = []
            spills = []
            funcargs = []
            float_count = 0
            int_count = 0
            for i in range(8):
                if case & (1<<i):
                    args.append('f%d' % float_count)
                    spills.append('force_spill(f%d)' % float_count)
                    float_count += 1
                    funcargs.append(F)
                else:
                    args.append('i%d' % int_count)
                    spills.append('force_spill(i%d)' % int_count)
                    int_count += 1
                    funcargs.append(I)

            arguments = ', '.join(args)
            spill_ops = '\n'.join(spills)

            FUNC = self.FuncType(funcargs, F)
            FPTR = self.Ptr(FUNC)
            func_ptr = llhelper(FPTR, func)
            calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                        EffectInfo.MOST_GENERAL)
            funcbox = self.get_funcbox(cpu, func_ptr)

            ops = '[%s]\n' % arguments
            ops += '%s\n' % spill_ops
            ops += 'f99 = call(ConstClass(func_ptr), %s, descr=calldescr)\n' % arguments
            ops += 'finish(f99, %s)\n' % arguments

            loop = parse(ops, namespace=locals())
            looptoken = JitCellToken()
            done_number = self.cpu.get_fail_descr_number(loop.operations[-1].getdescr())
            self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
            argvals, expected_result = self._prepare_args(args, floats, ints)

            res = self.cpu.execute_token(looptoken, *argvals)
            x = longlong.getrealfloat(cpu.get_latest_value_float(0))
            assert abs(x - expected_result) < 0.0001
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:58,代码来源:calling_convention_test.py


示例17: parse

def parse(vm):
    (xml_o, nodes_mod),_ = vm.decode_args("SM")
    assert isinstance(xml_o, Con_String)
    
    with lltype.scoped_alloc(xmlSAXHandler, zero=True) as h:
        h.c_initialized = rffi.r_uint(XML_SAX2_MAGIC)
        h.c_characters = llhelper(charactersSAXFuncP, _characters)
        h.c_startElementNs = llhelper(startElementNsSAX2FuncP, _start_element)
        h.c_endElementNs = llhelper(endElementNsSAX2FuncP, _end_element)
        docs_eo = Con_List(vm, [])
        _storage_hack.push(_Store(vm, [docs_eo], nodes_mod))
        r = xmlSAXUserParseMemory(h, lltype.nullptr(rffi.VOIDP.TO), xml_o.v, len(xml_o.v))
    if r < 0 or len(_storage_hack.peek().elems_stack) != 1:
        raise Exception("XXX")
    _storage_hack.pop()
    doc_o = vm.get_slot_apply(nodes_mod.get_defn(vm, "Doc"), "new", [docs_eo])
    
    return doc_o
开发者ID:cfbolz,项目名称:converge,代码行数:18,代码来源:libXML2.py


示例18: test_call_with_singlefloats

    def test_call_with_singlefloats(self):
        cpu = self.cpu
        if not cpu.supports_floats or not cpu.supports_singlefloats:
            py.test.skip('requires floats and singlefloats')

        import random
        from pypy.rlib.libffi import types
        from pypy.rlib.rarithmetic import r_singlefloat

        def func(*args):
            res = 0.0
            for i, x in enumerate(args):
                res += (i + 1.1) * float(x)
            return res

        F = lltype.Float
        S = lltype.SingleFloat
        I = lltype.Signed
        floats = [random.random() - 0.5 for i in range(8)]
        singlefloats = [r_singlefloat(random.random() - 0.5) for i in range(8)]
        ints = [random.randrange(-99, 99) for i in range(8)]
        for repeat in range(100):
            args = []
            argvalues = []
            argslist = []
            local_floats = list(floats)
            local_singlefloats = list(singlefloats)
            local_ints = list(ints)
            for i in range(8):
                case = random.randrange(0, 3)
                if case == 0:
                    args.append(F)
                    arg = local_floats.pop()
                    argslist.append(boxfloat(arg))
                elif case == 1:
                    args.append(S)
                    arg = local_singlefloats.pop()
                    argslist.append(BoxInt(longlong.singlefloat2int(arg)))
                else:
                    args.append(I)
                    arg = local_ints.pop()
                    argslist.append(BoxInt(arg))
                argvalues.append(arg)
            FUNC = self.FuncType(args, F)
            FPTR = self.Ptr(FUNC)
            func_ptr = llhelper(FPTR, func)
            calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                        EffectInfo.MOST_GENERAL)
            funcbox = self.get_funcbox(cpu, func_ptr)

            res = self.execute_operation(rop.CALL,
                                         [funcbox] + argslist,
                                         'float', descr=calldescr)
            expected = func(*argvalues)
            assert abs(res.getfloat() - expected) < 0.0001
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:55,代码来源:calling_convention_test.py


示例19: subtype_dealloc

def subtype_dealloc(space, obj):
    pto = obj.c_ob_type
    base = pto
    this_func_ptr = llhelper(subtype_dealloc.api_func.functype,
            subtype_dealloc.api_func.get_wrapper(space))
    while base.c_tp_dealloc == this_func_ptr:
        base = base.c_tp_base
        assert base
    dealloc = base.c_tp_dealloc
    # XXX call tp_del if necessary
    generic_cpy_call(space, dealloc, obj)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:typeobject.py


示例20: new

 def new(self, thrd, callback, arg):
     self.thrd = thrd._thrd
     self.runfn = callback
     self.arg = arg
     # make a fresh new clean SUSPSTACK
     newsuspstack = lltype.malloc(SUSPSTACK)
     newsuspstack.handle = _c.null_handle
     self.suspstack = newsuspstack
     # Invoke '_new_callback' by closing the stack
     h = pypy_asm_stackwalk2(llhelper(FUNCNOARG_P, _new_callback),
                             alternateanchor)
     return self.get_result_suspstack(h)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:12,代码来源:_stacklet_asmgcc.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python annlowlevel.llstr函数代码示例发布时间:2022-05-27
下一篇:
Python annlowlevel.hlstr函数代码示例发布时间: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