def define_hash_varsized(self): S = lltype.GcStruct('S', ('abc', lltype.Signed), ('def', lltype.Array(lltype.Signed))) s = lltype.malloc(S, 3, zero=True) h_s = lltype.identityhash(s) def f(): return lltype.identityhash(s) - h_s # != 0 (so far), # because S is a varsized structure. return f
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 _ll_1_gc_identityhash(x): return lltype.identityhash(x)
def f(): return lltype.identityhash(s) - h_s # != 0 (so far),
def _get_hash_(self): if self.value: return lltype.identityhash(self.value) else: return 0
def f(): obj1 = lltype.malloc(A) obj2 = lltype.malloc(A) return lltype.identityhash(obj1) == lltype.identityhash(obj2)
def rd_hash(ref): assert ref return lltype.identityhash(ref)
def ll_inst_hash(ins): if not ins: return 0 # for None else: from pypy.rpython.lltypesystem import lltype return lltype.identityhash(ins) # also works for ootype