def fn(): s = lltype.malloc(S) s.x = 10 s.t.z = 1 px = lltype.direct_fieldptr(s, 'x') py = lltype.direct_fieldptr(s, 'y') pz = lltype.direct_fieldptr(s.t, 'z') py[0] = 31 return px[0] + s.y + pz[0]
def ref(self, struct): if lltype.typeOf(struct).TO != self.TYPE: struct = lltype.cast_pointer(lltype.Ptr(self.TYPE), struct) FIELD = getattr(self.TYPE, self.fldname) if isinstance(FIELD, lltype.ContainerType): return getattr(struct, self.fldname) else: return lltype.direct_fieldptr(struct, self.fldname)
def direct_fieldptr(s_p, s_fieldname): assert isinstance(s_p, SomePtr), "direct_* of non-pointer: %r" % s_p assert s_fieldname.is_constant() cast_p = lltype.direct_fieldptr(s_p.ll_ptrtype._example(), s_fieldname.const) return SomePtr(ll_ptrtype=lltype.typeOf(cast_p))
def fn(): s = lltype.malloc(S) s.x = 11 p = lltype.direct_fieldptr(s, 'x') return p[0]
def op_direct_fieldptr(obj, field): checkptr(obj) assert isinstance(field, str) return lltype.direct_fieldptr(obj, field)
def walk_page(self, page, block_size, ok_to_free_func): """Walk over all objects in a page, and ask ok_to_free_func().""" # # 'freeblock' is the next free block freeblock = page.freeblock # # 'prevfreeblockat' is the address of where 'freeblock' was read from. prevfreeblockat = lltype.direct_fieldptr(page, 'freeblock') prevfreeblockat = llmemory.cast_ptr_to_adr(prevfreeblockat) # obj = llarena.getfakearenaaddress(llmemory.cast_ptr_to_adr(page)) obj += self.hdrsize surviving = 0 # initially skip_free_blocks = page.nfree # while True: # if obj == freeblock: # if skip_free_blocks == 0: # # 'obj' points to the first uninitialized block, # or to the end of the page if there are none. break # # 'obj' points to a free block. It means that # 'prevfreeblockat.address[0]' does not need to be updated. # Just read the next free block from 'obj.address[0]'. skip_free_blocks -= 1 prevfreeblockat = obj freeblock = obj.address[0] # else: # 'obj' points to a valid object. ll_assert(freeblock > obj, "freeblocks are linked out of order") # if ok_to_free_func(obj): # # The object should die. llarena.arena_reset(obj, _dummy_size(block_size), 0) llarena.arena_reserve(obj, llmemory.sizeof(llmemory.Address)) # Insert 'obj' in the linked list of free blocks. prevfreeblockat.address[0] = obj prevfreeblockat = obj obj.address[0] = freeblock # # Update the number of free objects in the page. page.nfree += 1 # else: # The object survives. surviving += 1 # obj += block_size # # Update the global total size of objects. self.total_memory_used += r_uint(surviving * block_size) # # Return the number of surviving objects. return surviving
def fn(): p1 = lltype.direct_fieldptr(s1, 'x') return p1[0]