def fn(): a = ootype.new(A) ahash = ootype.identityhash(a) obj = ootype.cast_to_object(a) native = cast_to_native_object(obj) name = native.GetType().get_Name() obj2 = cast_from_native_object(native) a2 = ootype.cast_from_object(A, obj2) a2hash = ootype.identityhash(a2) return name, ahash == a2hash
def hash_whatever(TYPE, x): # Hash of lltype or ootype object. # Only supports strings, unicodes and regular instances, # as well as primitives that can meaningfully be cast to Signed. if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc': if TYPE.TO is rstr.STR or TYPE.TO is rstr.UNICODE: return rstr.LLHelpers.ll_strhash(x) # assumed not null else: if x: return lltype.identityhash(x) else: return 0 elif TYPE is ootype.String or TYPE is ootype.Unicode: return x.ll_hash() elif isinstance(TYPE, ootype.OOType): if x: return ootype.identityhash(x) else: return 0 else: return rffi.cast(lltype.Signed, x)
def _get_hash_(self): if self.value: return ootype.identityhash(self.value) else: return 0
def f(): obj1 = ootype.new(A) obj2 = ootype.new(A) return ootype.identityhash(obj1) == ootype.identityhash(obj2)