예제 #1
0
파일: rgc.py 프로젝트: ieure/pypy
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 pypy.rpython.annlowlevel import base_ptr_lltype
        from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
        from pypy.rpython.lltypesystem import rclass
        if _is_rpy_instance(gcref):
            objptr = lltype.cast_opaque_ptr(base_ptr_lltype(), gcref)
            if objptr.typeptr:   # may be NULL, e.g. in rdict's dummykeyobj
                clsptr = _get_llcls_from_cls(Class)
                if rclass.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
예제 #2
0
파일: rgc.py 프로젝트: purepython/pypy
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 pypy.rpython.annlowlevel import base_ptr_lltype
        from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
        from pypy.rpython.lltypesystem import rclass
        if _is_rpy_instance(gcref):
            objptr = lltype.cast_opaque_ptr(base_ptr_lltype(), gcref)
            if objptr.typeptr:  # may be NULL, e.g. in rdict's dummykeyobj
                clsptr = _get_llcls_from_cls(Class)
                if rclass.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
예제 #3
0
 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)
예제 #4
0
 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)