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

Python llmemory.cast_adr_to_ptr函数代码示例

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

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



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

示例1: malloc_fixedsize

 def malloc_fixedsize(self, typeid16, size, can_collect,
                      has_finalizer=False, contains_weakptr=False):
     if can_collect:
         self.maybe_collect()
     size_gc_header = self.gcheaderbuilder.size_gc_header
     try:
         tot_size = size_gc_header + size
         usage = raw_malloc_usage(tot_size)
         bytes_malloced = ovfcheck(self.bytes_malloced+usage)
         ovfcheck(self.heap_usage + bytes_malloced)
     except OverflowError:
         raise memoryError
     result = raw_malloc(tot_size)
     if not result:
         raise memoryError
     hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
     hdr.typeid16 = typeid16
     hdr.mark = False
     hdr.flags = '\x00'
     if has_finalizer:
         hdr.next = self.malloced_objects_with_finalizer
         self.malloced_objects_with_finalizer = hdr
     elif contains_weakptr:
         hdr.next = self.objects_with_weak_pointers
         self.objects_with_weak_pointers = hdr
     else:
         hdr.next = self.malloced_objects
         self.malloced_objects = hdr
     self.bytes_malloced = bytes_malloced
     result += size_gc_header
     #llop.debug_print(lltype.Void, 'malloc typeid', typeid16,
     #                 '->', llmemory.cast_adr_to_int(result))
     self.write_malloc_statistics(typeid16, tot_size, result, False)
     return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
开发者ID:alkorzt,项目名称:pypy,代码行数:34,代码来源:marksweep.py


示例2: ll_memcpy

def ll_memcpy(dst, src, length):
    C_ARRAY = lltype.Ptr(lltype.FixedSizeArray(lltype.Char, 1))
    c_src = llmemory.cast_adr_to_ptr(src, C_ARRAY)
    c_dst = llmemory.cast_adr_to_ptr(dst, C_ARRAY)
    for i in range(length):
        c_dst[i] = c_src[i]
    return dst
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_rfunc.py


示例3: malloc_varsize_clear

 def malloc_varsize_clear(self, typeid16, length, size, itemsize,
                          offset_to_length, can_collect):
     if can_collect:
         self.maybe_collect()
     size_gc_header = self.gcheaderbuilder.size_gc_header
     try:
         fixsize = size_gc_header + size
         varsize = ovfcheck(itemsize * length)
         tot_size = ovfcheck(fixsize + varsize)
         usage = raw_malloc_usage(tot_size)
         bytes_malloced = ovfcheck(self.bytes_malloced+usage)
         ovfcheck(self.heap_usage + bytes_malloced)
     except OverflowError:
         raise memoryError
     result = raw_malloc(tot_size)
     if not result:
         raise memoryError
     raw_memclear(result, tot_size)        
     (result + size_gc_header + offset_to_length).signed[0] = length
     hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
     hdr.typeid16 = typeid16
     hdr.mark = False
     hdr.flags = '\x00'
     hdr.next = self.malloced_objects
     self.malloced_objects = hdr
     self.bytes_malloced = bytes_malloced
         
     result += size_gc_header
     #llop.debug_print(lltype.Void, 'malloc_varsize length', length,
     #                 'typeid', typeid16,
     #                 '->', llmemory.cast_adr_to_int(result))
     self.write_malloc_statistics(typeid16, tot_size, result, True)
     return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:marksweep.py


示例4: markcompactcollect

 def markcompactcollect(self, needed=0):
     start_time = self.debug_collect_start()
     self.debug_check_consistency()
     self.to_see = self.AddressStack()
     self.mark_roots_recursively()
     if (self.objects_with_finalizers.non_empty() or
         self.run_finalizers.non_empty()):
         self.mark_objects_with_finalizers()
         self._trace_and_mark()
     self.to_see.delete()
     num_of_alive_objs = self.compute_alive_objects()
     size_of_alive_objs = self.totalsize_of_objs
     totalsize = self.new_space_size(size_of_alive_objs, needed +
                                     num_of_alive_objs * BYTES_PER_TID)
     tid_backup_size = (llmemory.sizeof(self.TID_BACKUP, 0) +
                        llmemory.sizeof(TID_TYPE) * num_of_alive_objs)
     used_space_now = self.next_collect_after + raw_malloc_usage(tid_backup_size)
     if totalsize >= self.space_size or used_space_now >= self.space_size:
         toaddr = self.double_space_size(totalsize)
         llarena.arena_reserve(toaddr + size_of_alive_objs, tid_backup_size)
         self.tid_backup = llmemory.cast_adr_to_ptr(
             toaddr + size_of_alive_objs,
             lltype.Ptr(self.TID_BACKUP))
         resizing = True
     else:
         toaddr = llarena.arena_new_view(self.space)
         llarena.arena_reserve(self.top_of_space, tid_backup_size)
         self.tid_backup = llmemory.cast_adr_to_ptr(
             self.top_of_space,
             lltype.Ptr(self.TID_BACKUP))
         resizing = False
     self.next_collect_after = totalsize
     weakref_offsets = self.collect_weakref_offsets()
     finaladdr = self.update_forward_pointers(toaddr, num_of_alive_objs)
     if (self.run_finalizers.non_empty() or
         self.objects_with_finalizers.non_empty()):
         self.update_run_finalizers()
     if self.objects_with_weakrefs.non_empty():
         self.invalidate_weakrefs(weakref_offsets)
     self.update_objects_with_id()
     self.compact(resizing)
     if not resizing:
         size = toaddr + self.space_size - finaladdr
         llarena.arena_reset(finaladdr, size, True)
     else:
         if we_are_translated():
             # because we free stuff already in raw_memmove, we
             # would get double free here. Let's free it anyway
             llarena.arena_free(self.space)
         llarena.arena_reset(toaddr + size_of_alive_objs, tid_backup_size,
                             True)
     self.space        = toaddr
     self.free         = finaladdr
     self.top_of_space = toaddr + self.next_collect_after
     self.debug_check_consistency()
     self.tid_backup = lltype.nullptr(self.TID_BACKUP)
     if self.run_finalizers.non_empty():
         self.execute_finalizers()
     self.debug_collect_finish(start_time)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:59,代码来源:markcompact.py


示例5: ll_dealloc

 def ll_dealloc(addr):
     # bump refcount to 1
     gcheader = llmemory.cast_adr_to_ptr(addr - gc_header_offset, HDRPTR)
     gcheader.refcount = 1
     v = llmemory.cast_adr_to_ptr(addr, QUERY_ARG_TYPE)
     rtti = queryptr(v)
     gcheader.refcount = 0
     llop.gc_call_rtti_destructor(lltype.Void, rtti, addr)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:refcounting.py


示例6: cast_adr_to_int

 def cast_adr_to_int(self, adr):
     if not adr:
         return 0
     try:
         ptr = llmemory.cast_adr_to_ptr(adr, gc_ll_descr.WB_FUNCPTR)
         assert ptr._obj._callable == \
                llop1._write_barrier_failing_case
         return 42
     except lltype.InvalidCast:
         ptr = llmemory.cast_adr_to_ptr(
             adr, gc_ll_descr.WB_ARRAY_FUNCPTR)
         assert ptr._obj._callable == \
                llop1._write_barrier_from_array_failing_case
         return 43
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:14,代码来源:test_gc.py


示例7: test_look_inside_object

def test_look_inside_object():
    # this code is also used in translation tests below
    myarenasize = 50
    a = arena_malloc(myarenasize, False)
    b = a + round_up_for_allocation(llmemory.sizeof(lltype.Char))
    arena_reserve(b, precomputed_size)
    (b + llmemory.offsetof(SX, 'x')).signed[0] = 123
    assert llmemory.cast_adr_to_ptr(b, SPTR).x == 123
    llmemory.cast_adr_to_ptr(b, SPTR).x += 1
    assert (b + llmemory.offsetof(SX, 'x')).signed[0] == 124
    arena_reset(a, myarenasize, True)
    arena_reserve(b, round_up_for_allocation(llmemory.sizeof(SX)))
    assert llmemory.cast_adr_to_ptr(b, SPTR).x == 0
    arena_free(a)
    return 42
开发者ID:antoine1fr,项目名称:pygirl,代码行数:15,代码来源:test_llarena.py


示例8: _mark_root_and_clear_bit

 def _mark_root_and_clear_bit(self, root):
     gcobjectaddr = root.address[0]
     self._mark_stack.append(gcobjectaddr)
     size_gc_header = self.gcheaderbuilder.size_gc_header
     gc_info = gcobjectaddr - size_gc_header
     hdr = llmemory.cast_adr_to_ptr(gc_info, self.HDRPTR)
     hdr.mark = False
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:marksweep.py


示例9: get_forwarding_address

 def get_forwarding_address(self, obj):
     tid = self.header(obj).tid
     if tid & GCFLAG_IMMORTAL:
         return obj      # prebuilt objects are "forwarded" to themselves
     else:
         stub = llmemory.cast_adr_to_ptr(obj, self.FORWARDSTUBPTR)
         return stub.forw
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:semispace.py


示例10: init_gc_object_immortal

 def init_gc_object_immortal(self, addr, typeid16, flags=0):
     hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
     flags |= GCFLAG_HASHTAKEN | GCFLAG_MARKBIT
     # All prebuilt GC objects have the GCFLAG_MARKBIT always set.
     # That's convenient to make the GC always think that they
     # survive the current collection.
     hdr.tid = self.combine(typeid16, flags)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:markcompact.py


示例11: llf

 def llf(n):
     a = malloc(A, 5)
     a[3].x = 42
     adr_s = llmemory.cast_ptr_to_adr(a[0])
     adr_s += size * n
     s = llmemory.cast_adr_to_ptr(adr_s, PS)
     return s.x
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_lltyped.py


示例12: malloc_resizable_buffer

 def malloc_resizable_buffer(self, TYPE, n):
     typeid = self.get_type_id(TYPE)
     addr = self.gc.malloc(typeid, n)
     result = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
     if not self.gc.malloc_zero_filled:
         gctypelayout.zero_gc_pointers(result)
     return result
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:gcwrapper.py


示例13: f

 def f():
     adr = lladdress.raw_malloc(sizeofs)
     s = llmemory.cast_adr_to_ptr(adr, STRUCTPTR)
     s.y = 5 # does not crash
     result = (adr + offsety).signed[0] * 10 + int(offsety < sizeofs)
     lladdress.raw_free(adr)
     return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_symbolic.py


示例14: init_gc_object_immortal

 def init_gc_object_immortal(self, addr, typeid, flags=0):
     # prebuilt gc structures always have the mark bit set
     # ignore flags
     hdr = llmemory.cast_adr_to_ptr(addr, self.HDRPTR)
     hdr.typeid16 = typeid
     hdr.mark = True
     hdr.flags = '\x00'
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:marksweep.py


示例15: op_gc_reload_possibly_moved

 def op_gc_reload_possibly_moved(self, v_newaddr, v_ptr):
     assert v_newaddr.concretetype is llmemory.Address
     assert isinstance(v_ptr.concretetype, lltype.Ptr)
     assert v_ptr.concretetype.TO._gckind == 'gc'
     newaddr = self.getval(v_newaddr)
     p = llmemory.cast_adr_to_ptr(newaddr, v_ptr.concretetype)
     self.setvar(v_ptr, p)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:llinterp.py


示例16: walk_marked_objects

 def walk_marked_objects(self, callback):
     num = 0
     size_gc_header = self.gcheaderbuilder.size_gc_header
     fromaddr = self.space
     toaddr = self.base_forwarding_addr
     while fromaddr < self.free:
         hdr = llmemory.cast_adr_to_ptr(fromaddr, lltype.Ptr(self.HDR))
         obj = fromaddr + size_gc_header
         survives = self.marked(obj)
         if survives:
             typeid = self.get_typeid_from_backup(num)
             num += 1
         else:
             typeid = self.get_type_id(obj)
         baseobjsize = self._get_size_for_typeid(obj, typeid)
         basesize = size_gc_header + baseobjsize
         totalsrcsize = basesize
         #
         if survives:
             grow_hash_field = False
             if hdr.tid & GCFLAG_SAVED_HASHFIELD:
                 totalsrcsize += llmemory.sizeof(lltype.Signed)
             totaldstsize = totalsrcsize
             if hdr.tid & (GCFLAG_SAVED_HASHTAKEN | GCFLAG_SAVED_HASHFIELD) == GCFLAG_SAVED_HASHTAKEN:
                 if self.toaddr_smaller_than_fromaddr(toaddr, fromaddr):
                     grow_hash_field = True
                     totaldstsize += llmemory.sizeof(lltype.Signed)
             callback(self, obj, typeid, basesize, toaddr, grow_hash_field)
             toaddr += totaldstsize
         else:
             if hdr.tid & GCFLAG_HASHFIELD:
                 totalsrcsize += llmemory.sizeof(lltype.Signed)
         #
         fromaddr += totalsrcsize
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:34,代码来源:markcompact.py


示例17: link

 def link(pageaddr, size_class, size_block, nblocks, nusedblocks, step=1):
     assert step in (1, 2)
     llarena.arena_reserve(pageaddr, llmemory.sizeof(PAGE_HEADER))
     page = llmemory.cast_adr_to_ptr(pageaddr, PAGE_PTR)
     if step == 1:
         page.nfree = 0
         nuninitialized = nblocks - nusedblocks
     else:
         page.nfree = nusedblocks
         nuninitialized = nblocks - 2*nusedblocks
     page.freeblock = pageaddr + hdrsize + nusedblocks * size_block
     if nusedblocks < nblocks:
         chainedlists = ac.page_for_size
     else:
         chainedlists = ac.full_page_for_size
     page.nextpage = chainedlists[size_class]
     page.arena = ac.current_arena
     chainedlists[size_class] = page
     if fill_with_objects:
         for i in range(0, nusedblocks*step, step):
             objaddr = pageaddr + hdrsize + i * size_block
             llarena.arena_reserve(objaddr, _dummy_size(size_block))
         if step == 2:
             prev = 'page.freeblock'
             for i in range(1, nusedblocks*step, step):
                 holeaddr = pageaddr + hdrsize + i * size_block
                 llarena.arena_reserve(holeaddr,
                                       llmemory.sizeof(llmemory.Address))
                 exec '%s = holeaddr' % prev in globals(), locals()
                 prevhole = holeaddr
                 prev = 'prevhole.address[0]'
             endaddr = pageaddr + hdrsize + 2*nusedblocks * size_block
             exec '%s = endaddr' % prev in globals(), locals()
     assert ac._nuninitialized(page, size_class) == nuninitialized
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:34,代码来源:test_minimarkpage.py


示例18: do_getsetarrayitem

    def do_getsetarrayitem(self, op, oopspec):
        ffitypeval = self.getvalue(op.getarg(1))
        widthval = self.getvalue(op.getarg(2))
        offsetval = self.getvalue(op.getarg(5))
        if not ffitypeval.is_constant() or not widthval.is_constant() or not offsetval.is_constant():
            return [op]

        ffitypeaddr = ffitypeval.box.getaddr()
        ffitype = llmemory.cast_adr_to_ptr(ffitypeaddr, clibffi.FFI_TYPE_P)
        offset = offsetval.box.getint()
        width = widthval.box.getint()
        descr = self._get_interior_descr(ffitype, width, offset)

        arglist = [
            self.getvalue(op.getarg(3)).force_box(self.optimizer),
            self.getvalue(op.getarg(4)).force_box(self.optimizer),
        ]
        if oopspec == EffectInfo.OS_LIBFFI_GETARRAYITEM:
            opnum = rop.GETINTERIORFIELD_RAW
        elif oopspec == EffectInfo.OS_LIBFFI_SETARRAYITEM:
            opnum = rop.SETINTERIORFIELD_RAW
            arglist.append(self.getvalue(op.getarg(6)).force_box(self.optimizer))
        else:
            assert False
        return [
            ResOperation(opnum, arglist, op.result, descr=descr),
        ]
开发者ID:MichaelBlume,项目名称:pypy,代码行数:27,代码来源:fficall.py


示例19: malloc_fixedsize_clear

 def malloc_fixedsize_clear(self, typeid, size, can_collect,
                            has_finalizer=False, contains_weakptr=False):
     if (has_finalizer or not can_collect or
         (raw_malloc_usage(size) > self.lb_young_var_basesize and
          raw_malloc_usage(size) > self.largest_young_fixedsize)):
         # ^^^ we do two size comparisons; the first one appears redundant,
         #     but it can be constant-folded if 'size' is a constant; then
         #     it almost always folds down to False, which kills the
         #     second comparison as well.
         ll_assert(not contains_weakptr, "wrong case for mallocing weakref")
         # "non-simple" case or object too big: don't use the nursery
         return SemiSpaceGC.malloc_fixedsize_clear(self, typeid, size,
                                                   can_collect,
                                                   has_finalizer,
                                                   contains_weakptr)
     size_gc_header = self.gcheaderbuilder.size_gc_header
     totalsize = size_gc_header + size
     result = self.nursery_free
     if raw_malloc_usage(totalsize) > self.nursery_top - result:
         result = self.collect_nursery()
     llarena.arena_reserve(result, totalsize)
     # GCFLAG_NO_YOUNG_PTRS is never set on young objs
     self.init_gc_object(result, typeid, flags=0)
     self.nursery_free = result + totalsize
     if contains_weakptr:
         self.young_objects_with_weakrefs.append(result + size_gc_header)
     return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:27,代码来源:generation.py


示例20: malloc_varsize_slowpath

 def malloc_varsize_slowpath(self, typeid, length, force_nonmovable=False):
     # For objects that are too large, or when the nursery is exhausted.
     # In order to keep malloc_varsize_clear() as compact as possible,
     # we recompute what we need in this slow path instead of passing
     # it all as function arguments.
     size_gc_header = self.gcheaderbuilder.size_gc_header
     nonvarsize = size_gc_header + self.fixed_size(typeid)
     itemsize = self.varsize_item_sizes(typeid)
     offset_to_length = self.varsize_offset_to_length(typeid)
     try:
         varsize = ovfcheck(itemsize * length)
         totalsize = ovfcheck(nonvarsize + varsize)
     except OverflowError:
         raise MemoryError()
     if self.has_gcptr_in_varsize(typeid):
         nonlarge_max = self.nonlarge_gcptrs_max
     else:
         nonlarge_max = self.nonlarge_max
     if force_nonmovable or raw_malloc_usage(totalsize) > nonlarge_max:
         result = self.malloc_varsize_marknsweep(totalsize)
         flags = self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS | GCFLAG_UNVISITED
     else:
         result = self.malloc_varsize_collecting_nursery(totalsize)
         flags = self.GCFLAGS_FOR_NEW_YOUNG_OBJECTS
     self.init_gc_object(result, typeid, flags)
     (result + size_gc_header + offset_to_length).signed[0] = length
     return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
开发者ID:ieure,项目名称:pypy,代码行数:27,代码来源:hybrid.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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