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)
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)
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
def try_cast_gcref_to_instance(Class, gcref): # Before translation, unwraps the RPython instance contained in a _GcRef. # After translation, it is a type-check performed by the GC. if we_are_translated(): from rpython.rtyper.rclass import OBJECTPTR, ll_isinstance from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance if _is_rpy_instance(gcref): objptr = lltype.cast_opaque_ptr(OBJECTPTR, gcref) if objptr.typeptr: # may be NULL, e.g. in rdict's dummykeyobj clsptr = _get_llcls_from_cls(Class) if ll_isinstance(objptr, clsptr): return cast_base_ptr_to_instance(Class, objptr) return None else: if isinstance(gcref._x, Class): return gcref._x return None
def instanceOf(self, instbox, clsbox): adr = clsbox.getaddr() bounding_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE) real_instance = instbox.getref(rclass.OBJECTPTR) return rclass.ll_isinstance(real_instance, bounding_class)