예제 #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 = adr2int(a)
    assert lltype.typeOf(i) is lltype.Signed
    a2 = int2adr(i)
    assert llmemory.cast_adr_to_ptr(a2, lltype.Ptr(X)) == x
    assert adr2int(llmemory.NULL) == 0
    assert int2adr(0) == llmemory.NULL
예제 #2
0
파일: descr.py 프로젝트: zcxowwww/pypy
 def is_valid_class_for(self, struct):
     objptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
     cls = llmemory.cast_adr_to_ptr(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)
예제 #3
0
파일: history.py 프로젝트: soIu/rpython
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 = int2adr(i)
        try:
            return llmemory.cast_adr_to_int(adr, "emulated")
        except NotCtypesAllocatedStructure:
            return 12345 # use an arbitrary number for the hash
    return i
예제 #4
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 = 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())
예제 #5
0
파일: history.py 프로젝트: soIu/rpython
 def getaddr(self):
     return int2adr(self.value)
예제 #6
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 = int2adr(func)
         self.see_raw_object(func.ptr)
예제 #7
0
 def _funcptr_for_oopspec_memo(self, oopspecindex):
     _, func_as_int = self.callinfo_for_oopspec(oopspecindex)
     funcadr = int2adr(func_as_int)
     return funcadr.ptr