Example #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
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
Example #3
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] == 'calldescr-%d' % effectinfo.EffectInfo.OS_UNI_CONCAT
    assert op1.args[2] == ListOfKind('ref', [v1, v2])
    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[1]  # the calldescr
    assert heaptracker.int2adr(got[2]) == llmemory.cast_ptr_to_adr(func)
Example #4
0
def make_hashable_int(i):
    from pypy.rpython.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
Example #5
0
def make_hashable_int(i):
    from pypy.rpython.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
Example #6
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] == "calldescr-%d" % effectinfo.EffectInfo.OS_UNI_CONCAT
    assert op1.args[2] == ListOfKind("ref", [v1, v2])
    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[1]  # the calldescr
    assert heaptracker.int2adr(got[2]) == llmemory.cast_ptr_to_adr(func)
Example #7
0
 def _funcptr_for_oopspec_memo(self, oopspecindex):
     from pypy.jit.codewriter import heaptracker
     _, func_as_int = self.callinfo_for_oopspec(oopspecindex)
     funcadr = heaptracker.int2adr(func_as_int)
     return funcadr.ptr
Example #8
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)
Example #9
0
 def getaddr(self):
     return heaptracker.int2adr(self.value)
Example #10
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)
Example #11
0
 def _funcptr_for_oopspec_memo(self, oopspecindex):
     from pypy.jit.codewriter import heaptracker
     _, func_as_int = self.callinfo_for_oopspec(oopspecindex)
     funcadr = heaptracker.int2adr(func_as_int)
     return funcadr.ptr
Example #12
0
 def getaddr(self):
     return heaptracker.int2adr(self.value)