Пример #1
0
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
Пример #2
0
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
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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())
Пример #8
0
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())
Пример #9
0
 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
Пример #10
0
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)
Пример #11
0
 def getaddr(self):
     return heaptracker.int2adr(self.value)
Пример #12
0
 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)
Пример #13
0
 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
Пример #14
0
 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)
Пример #15
0
 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
Пример #16
0
 def getaddr(self):
     return heaptracker.int2adr(self.value)