def test_cast_adr_to_int_and_back(): X = lltype.Struct('X', ('foo', lltype.Signed)) x = lltype.malloc(X, immortal=True) x.foo = 42 a = llmemory.cast_ptr_to_adr(x) i = heaptracker.adr2int(a) assert lltype.typeOf(i) is lltype.Signed a2 = heaptracker.int2adr(i) assert llmemory.cast_adr_to_ptr(a2, lltype.Ptr(X)) == x assert heaptracker.adr2int(llmemory.NULL) == 0 assert heaptracker.int2adr(0) == llmemory.NULL
def is_valid_class_for(self, struct): objptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct) cls = llmemory.cast_adr_to_ptr(heaptracker.int2adr(self.get_vtable()), lltype.Ptr(rclass.OBJECT_VTABLE)) # this first comparison is necessary, since we want to make sure # that vtable for JitVirtualRef is the same without actually reading # fields return objptr.typeptr == cls or rclass.ll_isinstance(objptr, cls)
def is_valid_class_for(self, struct): objptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct) cls = llmemory.cast_adr_to_ptr( heaptracker.int2adr(self.get_vtable()), lltype.Ptr(rclass.OBJECT_VTABLE)) # this first comparison is necessary, since we want to make sure # that vtable for JitVirtualRef is the same without actually reading # fields return objptr.typeptr == cls or rclass.ll_isinstance(objptr, cls)
def make_hashable_int(i): from rpython.rtyper.lltypesystem.ll2ctypes import NotCtypesAllocatedStructure if not we_are_translated() and isinstance(i, llmemory.AddressAsInt): # Warning: such a hash changes at the time of translation adr = heaptracker.int2adr(i) try: return llmemory.cast_adr_to_int(adr, "emulated") except NotCtypesAllocatedStructure: return 12345 # use an arbitrary number for the hash return i
def unwrap(TYPE, box): if TYPE is lltype.Void: return None if isinstance(TYPE, lltype.Ptr): if TYPE.TO._gckind == "gc": return box.getref(TYPE) else: adr = heaptracker.int2adr(box.getint()) return llmemory.cast_adr_to_ptr(adr, TYPE) if TYPE == lltype.Float: return box.getfloat() else: return lltype.cast_primitive(TYPE, box.getint())
def check_correct_type(self, struct): if self.parent_descr.is_object(): cls = llmemory.cast_adr_to_ptr( heaptracker.int2adr(self.parent_descr.get_vtable()), lltype.Ptr(rclass.OBJECT_VTABLE)) tpptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct).typeptr # this comparison is necessary, since we want to make sure # that vtable for JitVirtualRef is the same without actually reading # fields if tpptr != cls: assert rclass.ll_isinstance(lltype.cast_opaque_ptr( rclass.OBJECTPTR, struct), cls) else: pass
def test_unicode_concat(): # test that the oopspec is present and correctly transformed PSTR = lltype.Ptr(rstr.UNICODE) FUNC = lltype.FuncType([PSTR, PSTR], PSTR) func = lltype.functionptr(FUNC, "ll_strconcat", _callable=rstr.LLHelpers.ll_strconcat) v1 = varoftype(PSTR) v2 = varoftype(PSTR) v3 = varoftype(PSTR) op = SpaceOperation("direct_call", [const(func), v1, v2], v3) cc = FakeBuiltinCallControl() tr = Transformer(FakeCPU(), cc) op1 = tr.rewrite_operation(op) assert op1.opname == "residual_call_r_r" assert op1.args[0].value == func assert op1.args[1] == ListOfKind("ref", [v1, v2]) assert op1.args[2] == "calldescr-%d" % effectinfo.EffectInfo.OS_UNI_CONCAT assert op1.result == v3 # # check the callinfo_for_oopspec got = cc.callinfocollection.seen[0] assert got[0] == effectinfo.EffectInfo.OS_UNI_CONCAT assert got[1] == op1.args[2] # the calldescr assert heaptracker.int2adr(got[2]) == llmemory.cast_ptr_to_adr(func)
def getaddr(self): return heaptracker.int2adr(self.value)
def finished(self, callinfocollection): # Helper called at the end of assembling. Registers the extra # functions shown in _callinfo_for_oopspec. for func in callinfocollection.all_function_addresses_as_int(): func = heaptracker.int2adr(func) self.see_raw_object(func.ptr)
def _funcptr_for_oopspec_memo(self, oopspecindex): from rpython.jit.codewriter import heaptracker _, func_as_int = self.callinfo_for_oopspec(oopspecindex) funcadr = heaptracker.int2adr(func_as_int) return funcadr.ptr