コード例 #1
0
 def fn(n):
     s = lltype.cast_int_to_ptr(PS, n)
     assert lltype.typeOf(s) == PS
     assert lltype.cast_ptr_to_int(s) == n
     t = lltype.cast_pointer(PT, s)
     assert lltype.typeOf(t) == PT
     assert lltype.cast_ptr_to_int(t) == n
     assert s == lltype.cast_pointer(PS, t)
コード例 #2
0
ファイル: test_rptr.py プロジェクト: Darriall/pypy
 def fn(n):
     s = lltype.cast_int_to_ptr(PS, n)
     assert lltype.typeOf(s) == PS
     assert lltype.cast_ptr_to_int(s) == n
     t = lltype.cast_pointer(PT, s)
     assert lltype.typeOf(t) == PT
     assert lltype.cast_ptr_to_int(t) == n
     assert s == lltype.cast_pointer(PS, t)
コード例 #3
0
ファイル: object.py プロジェクト: grubermeister/kamina-script
def PyObject_Realloc(space, ptr, size):
    if not lltype.cast_ptr_to_int(ptr):
        return lltype.malloc(rffi.VOIDP.TO, size,
                         flavor='raw',
                         add_memory_pressure=True)
    # XXX FIXME
    return realloc(ptr, size)
コード例 #4
0
ファイル: test_rtagged.py プロジェクト: sota/pypy-old
def test_instantiate():
    def fn1(n):
        return C(n)

    res = interpret(fn1, [42], taggedpointers=True)
    value = lltype.cast_ptr_to_int(res)
    assert value == 42 * 2 + 1  # for now
コード例 #5
0
def test_cast_adr_to_int():
    S = lltype.Struct('S')
    p = lltype.malloc(S, immortal=True)

    def fn(n):
        a = llmemory.cast_ptr_to_adr(p)
        if n == 2:
            return llmemory.cast_adr_to_int(a, "emulated")
        elif n == 4:
            return llmemory.cast_adr_to_int(a, "symbolic")
        else:
            return llmemory.cast_adr_to_int(a, "forced")

    res = interpret(fn, [2])
    assert is_valid_int(res)
    assert res == lltype.cast_ptr_to_int(p)
    #
    res = interpret(fn, [4])
    assert isinstance(res, llmemory.AddressAsInt)
    assert llmemory.cast_int_to_adr(res) == llmemory.cast_ptr_to_adr(p)
    #
    res = interpret(fn, [6])
    assert is_valid_int(res)
    from rpython.rtyper.lltypesystem import rffi
    assert res == rffi.cast(lltype.Signed, p)
コード例 #6
0
ファイル: rtagged.py プロジェクト: charred/pypy
def ll_unboxed_isinstance_const(obj, minid, maxid, answer_if_unboxed):
    if not obj:
        return False
    if lltype.cast_ptr_to_int(obj) & 1:
        return answer_if_unboxed
    else:
        return ll_issubclass_const(obj.typeptr, minid, maxid)
コード例 #7
0
def ll_unboxed_isinstance_const(obj, minid, maxid, answer_if_unboxed):
    if not obj:
        return False
    if lltype.cast_ptr_to_int(obj) & 1:
        return answer_if_unboxed
    else:
        return ll_issubclass_const(obj.typeptr, minid, maxid)
コード例 #8
0
ファイル: shadowstack.py プロジェクト: zielmicha/pypy
 def ll_attach(shadowstackref):
     """After prepare_free_slot(), store a shadowstackref in that slot."""
     index = fullstack_cache[0]
     ll_assert(index > 0, "fullstack attach: no free slot")
     fullstack_cache[0] = fullstack_cache[index]
     fullstack_cache[index] = lltype.cast_ptr_to_int(shadowstackref)
     ll_assert(shadowstackref.fsindex == 0, "fullstack attach: already one?")
     shadowstackref.fsindex = index    # > 0
コード例 #9
0
ファイル: rgc.py プロジェクト: yuanleilei/pypy
def cast_gcref_to_int(gcref):
    # This is meant to be used on cast_instance_to_gcref results.
    # Don't use this on regular gcrefs obtained e.g. with
    # lltype.cast_opaque_ptr().
    if we_are_translated():
        return lltype.cast_ptr_to_int(gcref)
    else:
        return id(gcref._x)
コード例 #10
0
def cast_gcref_to_int(gcref):
    # This is meant to be used on cast_instance_to_gcref results.
    # Don't use this on regular gcrefs obtained e.g. with
    # lltype.cast_opaque_ptr().
    if we_are_translated():
        return lltype.cast_ptr_to_int(gcref)
    else:
        return id(gcref._x)
コード例 #11
0
ファイル: rtagged.py プロジェクト: charred/pypy
 def ll_str(self, i):
     if lltype.cast_ptr_to_int(i) & 1:
         from rpython.rtyper.lltypesystem import rstr
         from rpython.rtyper.rint import signed_repr
         llstr1 = signed_repr.ll_str(ll_unboxed_to_int(i))
         return rstr.ll_strconcat(rstr.unboxed_instance_str_prefix,
                   rstr.ll_strconcat(llstr1,
                                     rstr.unboxed_instance_str_suffix))
     else:
         return InstanceRepr.ll_str(self, i)
コード例 #12
0
ファイル: shadowstack.py プロジェクト: zielmicha/pypy
 def ll_detach(shadowstackref):
     """Detach a shadowstackref from the array of MAX entries."""
     index = shadowstackref.fsindex
     ll_assert(index > 0, "detach: unattached shadowstackref")
     ll_assert(fullstack_cache[index] ==
               lltype.cast_ptr_to_int(shadowstackref),
               "detach: bad fullstack_cache")
     shadowstackref.fsindex = 0
     fullstack_cache[index] = fullstack_cache[0]
     fullstack_cache[0] = index
コード例 #13
0
 def ll_str(self, i):
     if lltype.cast_ptr_to_int(i) & 1:
         from rpython.rtyper.lltypesystem import rstr
         from rpython.rtyper.rint import signed_repr
         llstr1 = signed_repr.ll_str(ll_unboxed_to_int(i))
         return rstr.ll_strconcat(
             rstr.unboxed_instance_str_prefix,
             rstr.ll_strconcat(llstr1, rstr.unboxed_instance_str_suffix))
     else:
         return InstanceRepr.ll_str(self, i)
コード例 #14
0
 def set(value):
     assert isinstance(value, Cls) or value is None
     if we_are_translated():
         from rpython.rtyper.annlowlevel import cast_instance_to_gcref
         gcref = cast_instance_to_gcref(value)
         value = lltype.cast_ptr_to_int(gcref)
         setraw(value)
         rgc.register_custom_trace_hook(TRACETLREF, _lambda_trace_tlref)
         rgc.ll_writebarrier(_tracetlref_obj)
     else:
         self.local.value = value
コード例 #15
0
ファイル: fficurses.py プロジェクト: charred/pypy
def tigetstr_llimpl(cap):
    check_setup_invoked()
    ll_cap = rffi.str2charp(cap)
    try:
        ll_res = c_tigetstr(ll_cap)
        num = lltype.cast_ptr_to_int(ll_res)
        if num == 0 or num == -1:
            raise interp_curses.TermError()
        res = rffi.charp2str(ll_res)
        return res
    finally:
        rffi.free_charp(ll_cap)
コード例 #16
0
def tigetstr_llimpl(cap):
    check_setup_invoked()
    ll_cap = rffi.str2charp(cap)
    try:
        ll_res = c_tigetstr(ll_cap)
        num = lltype.cast_ptr_to_int(ll_res)
        if num == 0 or num == -1:
            raise interp_curses.TermError()
        res = rffi.charp2str(ll_res)
        return res
    finally:
        rffi.free_charp(ll_cap)
コード例 #17
0
ファイル: shadowstack.py プロジェクト: zielmicha/pypy
 def customtrace(gc, obj, callback, arg):
     obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
     index = obj.fsindex
     if index > 0:
         # Haaaaaaack: fullstack_cache[] is just an integer, so it
         # doesn't follow the SHADOWSTACKREF when it moves.  But we
         # know this customtrace() will be called just after the
         # move.  So we fix the fullstack_cache[] now... :-/
         fullstack_cache[index] = lltype.cast_ptr_to_int(obj)
     addr = obj.top
     start = obj.base
     while addr != start:
         addr -= sizeofaddr
         gc._trace_callback(callback, arg, addr)
コード例 #18
0
 def set(value):
     assert isinstance(value, Cls) or value is None
     if we_are_translated():
         from rpython.rtyper.annlowlevel import cast_instance_to_gcref
         from rpython.rlib.rgc import _make_sure_does_not_move
         from rpython.rlib.objectmodel import running_on_llinterp
         gcref = cast_instance_to_gcref(value)
         if not running_on_llinterp:
             if gcref:
                 _make_sure_does_not_move(gcref)
         value = lltype.cast_ptr_to_int(gcref)
         setraw(value)
     else:
         self.local.value = value
コード例 #19
0
ファイル: compile.py プロジェクト: Mu-L/pypy
    def must_compile(self, deadframe, metainterp_sd, jitdriver_sd):
        jitcounter = metainterp_sd.warmrunnerdesc.jitcounter
        #
        if self.status & (self.ST_BUSY_FLAG | self.ST_TYPE_MASK) == 0:
            # common case: this is not a guard_value, and we are not
            # already busy tracing.  The rest of self.status stores a
            # valid per-guard index in the jitcounter.
            hash = self.status
            assert hash == (self.status & self.ST_SHIFT_MASK)
        #
        # do we have the BUSY flag?  If so, we're tracing right now, e.g. in an
        # outer invocation of the same function, so don't trace again for now.
        elif self.status & self.ST_BUSY_FLAG:
            return False
        #
        else:  # we have a GUARD_VALUE that fails.
            from rpython.rlib.objectmodel import current_object_addr_as_int

            index = intmask(self.status >> self.ST_SHIFT)
            typetag = intmask(self.status & self.ST_TYPE_MASK)

            # fetch the actual value of the guard_value, possibly turning
            # it to an integer
            if typetag == self.TY_INT:
                intval = metainterp_sd.cpu.get_value_direct(
                    deadframe, 'i', index)
            elif typetag == self.TY_REF:
                refval = metainterp_sd.cpu.get_value_direct(
                    deadframe, 'r', index)
                intval = lltype.cast_ptr_to_int(refval)
            elif typetag == self.TY_FLOAT:
                floatval = metainterp_sd.cpu.get_value_direct(
                    deadframe, 'f', index)
                intval = longlong.gethash_fast(floatval)
            else:
                assert 0, typetag

            if not we_are_translated():
                if isinstance(intval, llmemory.AddressAsInt):
                    intval = llmemory.cast_adr_to_int(
                        llmemory.cast_int_to_adr(intval), "forced")

            hash = r_uint(
                current_object_addr_as_int(self) * 777767777 +
                intval * 1442968193)
        #
        increment = jitdriver_sd.warmstate.increment_trace_eagerness
        return jitcounter.tick(hash, increment)
コード例 #20
0
ファイル: compile.py プロジェクト: abhinavthomas/pypy
    def must_compile(self, deadframe, metainterp_sd, jitdriver_sd):
        jitcounter = metainterp_sd.warmrunnerdesc.jitcounter
        #
        if self.status & (self.ST_BUSY_FLAG | self.ST_TYPE_MASK) == 0:
            # common case: this is not a guard_value, and we are not
            # already busy tracing.  The rest of self.status stores a
            # valid per-guard index in the jitcounter.
            hash = self.status
            assert hash == (self.status & self.ST_SHIFT_MASK)
        #
        # do we have the BUSY flag?  If so, we're tracing right now, e.g. in an
        # outer invocation of the same function, so don't trace again for now.
        elif self.status & self.ST_BUSY_FLAG:
            return False
        #
        else:    # we have a GUARD_VALUE that fails.
            from rpython.rlib.objectmodel import current_object_addr_as_int

            index = intmask(self.status >> self.ST_SHIFT)
            typetag = intmask(self.status & self.ST_TYPE_MASK)

            # fetch the actual value of the guard_value, possibly turning
            # it to an integer
            if typetag == self.TY_INT:
                intval = metainterp_sd.cpu.get_value_direct(deadframe, 'i',
                                                            index)
            elif typetag == self.TY_REF:
                refval = metainterp_sd.cpu.get_value_direct(deadframe, 'r',
                                                            index)
                intval = lltype.cast_ptr_to_int(refval)
            elif typetag == self.TY_FLOAT:
                floatval = metainterp_sd.cpu.get_value_direct(deadframe, 'f',
                                                              index)
                intval = longlong.gethash_fast(floatval)
            else:
                assert 0, typetag

            if not we_are_translated():
                if isinstance(intval, llmemory.AddressAsInt):
                    intval = llmemory.cast_adr_to_int(
                        llmemory.cast_int_to_adr(intval), "forced")

            hash = r_uint(current_object_addr_as_int(self) * 777767777 +
                          intval * 1442968193)
        #
        increment = jitdriver_sd.warmstate.increment_trace_eagerness
        return jitcounter.tick(hash, increment)
コード例 #21
0
ファイル: rclass.py プロジェクト: charred/pypy
 def ll_str(self, i): # doesn't work for non-gc classes!
     from rpython.rtyper.lltypesystem import rstr
     from rpython.rtyper.lltypesystem.ll_str import ll_int2hex
     from rpython.rlib.rarithmetic import r_uint
     if not i:
         return rstr.null_str
     instance = cast_pointer(OBJECTPTR, i)
     uid = r_uint(cast_ptr_to_int(i))
     nameLen = len(instance.typeptr.name)
     nameString = rstr.mallocstr(nameLen-1)
     i = 0
     while i < nameLen - 1:
         nameString.chars[i] = instance.typeptr.name[i]
         i += 1
     res =                        rstr.instance_str_prefix
     res = rstr.ll_strconcat(res, nameString)
     res = rstr.ll_strconcat(res, rstr.instance_str_infix)
     res = rstr.ll_strconcat(res, ll_int2hex(uid, False))
     res = rstr.ll_strconcat(res, rstr.instance_str_suffix)
     return res
コード例 #22
0
ファイル: test_rptr.py プロジェクト: Darriall/pypy
def test_cast_adr_to_int():
    S = lltype.Struct('S')
    p = lltype.malloc(S, immortal=True)
    def fn(n):
        a = llmemory.cast_ptr_to_adr(p)
        if n == 2:
            return llmemory.cast_adr_to_int(a, "emulated")
        elif n == 4:
            return llmemory.cast_adr_to_int(a, "symbolic")
        else:
            return llmemory.cast_adr_to_int(a, "forced")

    res = interpret(fn, [2])
    assert is_valid_int(res)
    assert res == lltype.cast_ptr_to_int(p)
    #
    res = interpret(fn, [4])
    assert isinstance(res, llmemory.AddressAsInt)
    assert llmemory.cast_int_to_adr(res) == llmemory.cast_ptr_to_adr(p)
    #
    res = interpret(fn, [6])
    assert is_valid_int(res)
    from rpython.rtyper.lltypesystem import rffi
    assert res == rffi.cast(lltype.Signed, p)
コード例 #23
0
def ll_unboxed_to_int(p):
    return lltype.cast_ptr_to_int(p) >> 1
コード例 #24
0
ファイル: test_rtagged.py プロジェクト: Darriall/pypy
def test_instantiate():
    def fn1(n):
        return C(n)
    res = interpret(fn1, [42], taggedpointers=True)
    value = lltype.cast_ptr_to_int(res)
    assert value == 42 * 2 + 1    # for now
コード例 #25
0
 def op_cast_ptr_to_int(self, ptr1):
     checkptr(ptr1)
     return lltype.cast_ptr_to_int(ptr1)
コード例 #26
0
 def fn(n):
     t = lltype.cast_int_to_ptr(PT, n)
     assert lltype.typeOf(t) == PT
     assert lltype.cast_ptr_to_int(t) == n
     o = lltype.cast_opaque_ptr(PQ, t)
     assert lltype.cast_ptr_to_int(o) == n
コード例 #27
0
 def id(self, ptr):
     return lltype.cast_ptr_to_int(ptr)
コード例 #28
0
ファイル: llinterp.py プロジェクト: pypyjs/pypy
 def op_cast_ptr_to_int(self, ptr1):
     checkptr(ptr1)
     return lltype.cast_ptr_to_int(ptr1)
コード例 #29
0
def ll_cls_hash(cls):
    return cast_ptr_to_int(cls)
コード例 #30
0
ファイル: rtagged.py プロジェクト: charred/pypy
def ll_unboxed_to_int(p):
    return lltype.cast_ptr_to_int(p) >> 1
コード例 #31
0
ファイル: rtagged.py プロジェクト: charred/pypy
def ll_unboxed_getclass(instance, class_if_unboxed):
    if lltype.cast_ptr_to_int(instance) & 1:
        return class_if_unboxed
    return instance.typeptr
コード例 #32
0
ファイル: test_llmemory.py プロジェクト: sota/pypy-old
 def f():
     ptr = lltype.malloc(A, 10)
     gcref = lltype.cast_opaque_ptr(GCREF, ptr)
     adr = lltype.cast_ptr_to_int(gcref)
     assert adr == lltype.cast_ptr_to_int(ptr)
コード例 #33
0
ファイル: rptr.py プロジェクト: charred/pypy
 def ll_str(self, p):
     from rpython.rtyper.lltypesystem.rstr import ll_str
     id = lltype.cast_ptr_to_int(p)
     return ll_str.ll_int2hex(r_uint(id), True)
コード例 #34
0
ファイル: test_llmemory.py プロジェクト: Darriall/pypy
 def f():
     ptr = lltype.malloc(A, 10)
     gcref = lltype.cast_opaque_ptr(GCREF, ptr)
     adr = lltype.cast_ptr_to_int(gcref)
     assert adr == lltype.cast_ptr_to_int(ptr)
コード例 #35
0
ファイル: base.py プロジェクト: timfel/thesis-data
 def id(self, ptr):
     return lltype.cast_ptr_to_int(ptr)
コード例 #36
0
def ll_unboxed_getclass(instance, class_if_unboxed):
    if lltype.cast_ptr_to_int(instance) & 1:
        return class_if_unboxed
    return instance.typeptr
コード例 #37
0
 def ll_str(self, p):
     from rpython.rtyper.lltypesystem.rstr import ll_str
     id = lltype.cast_ptr_to_int(p)
     return ll_str.ll_int2hex(r_uint(id), True)
コード例 #38
0
ファイル: rgc.py プロジェクト: charred/pypy
def cast_gcref_to_int(gcref):
    if we_are_translated():
        return lltype.cast_ptr_to_int(gcref)
    else:
        return id(gcref._x)
コード例 #39
0
ファイル: test_rptr.py プロジェクト: Darriall/pypy
 def fn(n):
     t = lltype.cast_int_to_ptr(PT, n)
     assert lltype.typeOf(t) == PT
     assert lltype.cast_ptr_to_int(t) == n
     o = lltype.cast_opaque_ptr(PQ, t)
     assert lltype.cast_ptr_to_int(o) == n