当前位置: 首页>>代码示例>>Python>>正文


Python lltype.cast_pointer函数代码示例

本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.cast_pointer函数的典型用法代码示例。如果您正苦于以下问题:Python cast_pointer函数的具体用法?Python cast_pointer怎么用?Python cast_pointer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cast_pointer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cast_pointer

def test_cast_pointer():
    S3 = lltype.GcStruct("s3", ('a', lltype.Signed))
    S2 = lltype.GcStruct("s3", ('sub', S3))
    S1 = lltype.GcStruct("s1", ('sub', S2))
    p1 = malloc(S1)
    p2 = p1.sub
    p3 = p2.sub
    p12 = cast_pointer(lltype.Ptr(S1), p2)
    assert p12 == p1
    p13 = cast_pointer(lltype.Ptr(S1), p3)
    assert p13 == p1
    p21 = cast_pointer(lltype.Ptr(S2), p1)
    assert p21 == p2
    p23 = cast_pointer(lltype.Ptr(S2), p3)
    assert p23 == p2
    p31 = cast_pointer(lltype.Ptr(S3), p1)
    assert p31 == p3
    p32 = cast_pointer(lltype.Ptr(S3), p2)
    assert p32 == p3
    p3 = malloc(S3)
    p2 = malloc(S2)
    S0 = lltype.GcStruct("s0", ('sub', S1))
    p0 = malloc(S0)
    assert p0 == cast_pointer(lltype.Ptr(S0), p0)
    p3 = cast_pointer(lltype.Ptr(S3), p0)
    p03 = cast_pointer(lltype.Ptr(S0), p3)
    assert p0 == p03
    S1bis = lltype.GcStruct("s1b", ('sub', S2))
    assert S1bis != S1
    p1b = malloc(S1bis)
    p3 = p1b.sub.sub
    assert p1b == cast_pointer(lltype.Ptr(S1bis), p3)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:32,代码来源:test_lltypesimulation.py

示例2: ll_getter

 def ll_getter(inst):
     top = lltype.cast_pointer(TOPPTR, inst)
     access = top.vable_access
     if access:
         return getattr(lltype.cast_pointer(ACCESSPTR, access),
                        'get_'+name)(top)
     else:
         return getattr(inst, name)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:rvirtualizable.py

示例3: DONOTtest_runtime_type_info

def DONOTtest_runtime_type_info():
    S = GcStruct('s', ('x', Signed))
    attachRuntimeTypeInfo(S)
    s = malloc(S)
    assert runtime_type_info(s) == getRuntimeTypeInfo(S)
    S1 = GcStruct('s1', ('sub', S), ('x', Signed))
    attachRuntimeTypeInfo(S1)
    s1 = malloc(S1)
    assert runtime_type_info(s1) == getRuntimeTypeInfo(S1)
    assert runtime_type_info(s1.sub) == getRuntimeTypeInfo(S1)
    assert runtime_type_info(cast_pointer(Ptr(S), s1)) == getRuntimeTypeInfo(S1)
    def dynamic_type_info_S(p):
        if p.x == 0:
            return getRuntimeTypeInfo(S)
        else:
            return getRuntimeTypeInfo(S1)
    fp = functionptr(FuncType([Ptr(S)], Ptr(RuntimeTypeInfo)), 
                     "dynamic_type_info_S", 
                     _callable=dynamic_type_info_S)
    attachRuntimeTypeInfo(S, fp)
    assert s.x == 0
    assert runtime_type_info(s) == getRuntimeTypeInfo(S)
    s.x = 1
    py.test.raises(RuntimeError, "runtime_type_info(s)")
    assert s1.sub.x == 0
    py.test.raises(RuntimeError, "runtime_type_info(s1.sub)")
    s1.sub.x = 1
    assert runtime_type_info(s1.sub) == getRuntimeTypeInfo(S1)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:28,代码来源:test_lltypesimulation.py

示例4: ll_type_setup

 def ll_type_setup(p):
     tp = lltype.cast_pointer(lltype.Ptr(PY_TYPE_OBJECT), p)
     old_flags = tp.c_tp_flags
     tp.c_tp_flags |= Py_TPFLAGS_HEAPTYPE
     for name, value in objects:
         llop.setattr(PyObjPtr, tp, name, value)
     tp.c_tp_flags = old_flags
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:rcpy.py

示例5: f

 def f(x):
     s = lltype.malloc(S)
     s.x = 123
     if x < 0:
         t = lltype.cast_pointer(lltype.Ptr(T), s)
         t.y += 1
     return s.x
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_mallocv.py

示例6: test_repr

def test_repr():
    S = lltype.GcStruct('S')
    T = lltype.GcStruct('T', ('header', S))
    t = lltype.malloc(T)
    s = lltype.cast_pointer(lltype.Ptr(S), t)
    const = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))
    assert const._getrepr_() == "*T"
开发者ID:enyst,项目名称:plexnet,代码行数:7,代码来源:test_history.py

示例7: op_debug_fatalerror

 def op_debug_fatalerror(self, ll_msg, ll_exc=None):
     msg = ''.join(ll_msg.chars)
     if ll_exc is None:
         raise LLFatalError(msg)
     else:
         ll_exc_type = lltype.cast_pointer(rclass.OBJECTPTR, ll_exc).typeptr
         raise LLFatalError(msg, LLException(ll_exc_type, ll_exc))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:llinterp.py

示例8: fill_into

 def fill_into(vablerti, s, base, vrti):
     s = lltype.cast_opaque_ptr(PTRTYPE, s)
     i = 0
     for desc in descs:
         v = vrti._read_field(vablerti, desc, base, i)
         tgt = lltype.cast_pointer(desc.PTRTYPE, s)
         setattr(tgt, desc.fieldname, v)
         i = i + 1
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:rcontainer.py

示例9: test_nullptr_cast

def test_nullptr_cast():
    S = lltype.Struct('s')
    p0 = nullptr(S)
    assert not p0
    S1 = lltype.Struct("s1", ('s', S))
    p10 = cast_pointer(lltype.Ptr(S1), p0)
    assert lltype.typeOf(p10) == lltype.Ptr(S1)
    assert not p10
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:test_lltypesimulation.py

示例10: ref

 def ref(self, struct):
     if lltype.typeOf(struct).TO != self.TYPE:
         struct = lltype.cast_pointer(lltype.Ptr(self.TYPE), struct)
     FIELD = getattr(self.TYPE, self.fldname)
     if isinstance(FIELD, lltype.ContainerType):
         return getattr(struct, self.fldname)
     else:
         return lltype.direct_fieldptr(struct, self.fldname)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:llmemory.py

示例11: set_field_touched

 def set_field_touched(struc, value):
     T = fielddesc.RESTYPE
     if fielddesc.canbevirtual and fielddesc.gcref:
         vable_rti = struc.vable_rti
         vable_rti = cast_base_ptr_to_instance(VirtualizableRTI, vable_rti)
         vable_rti.touched_ptr_field(struc.vable_base, j)
     struc = lltype.cast_pointer(fielddesc.PTRTYPE, struc)
     setattr(struc, fielddesc.fieldname, value)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:rvirtualizable.py

示例12: virtual_ref_during_tracing

 def virtual_ref_during_tracing(self, real_object):
     assert real_object
     vref = lltype.malloc(self.JIT_VIRTUAL_REF)
     p = lltype.cast_pointer(rclass.OBJECTPTR, vref)
     p.typeptr = self.jit_virtual_ref_vtable
     vref.virtual_token = self.TOKEN_NONE
     vref.forced = lltype.cast_opaque_ptr(rclass.OBJECTPTR, real_object)
     return lltype.cast_opaque_ptr(llmemory.GCREF, vref)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:virtualref.py

示例13: test_cast_simple_widening2

def test_cast_simple_widening2():
    S2 = lltype.GcStruct("s2", ('a', lltype.Signed))
    S1 = lltype.GcStruct("s1", ('sub1', S2))
    p1 = malloc(S1)
    p2 = p1.sub1
    assert lltype.typeOf(p2) == lltype.Ptr(S2)
    p3 = cast_pointer(lltype.Ptr(S1), p2)
    assert p3 == p1
    p2 = malloc(S2)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:test_lltypesimulation.py

示例14: get_ll_pyobjectptr

 def get_ll_pyobjectptr(self, rtyper):
     from pypy.rpython.rclass import getinstancerepr
     wrapperobj = self.instance
     rpython_obj = get_rpython_data(wrapperobj)
     rpython_cls = rpython_obj.__class__
     classdef = rtyper.annotator.bookkeeper.getuniqueclassdef(rpython_cls)
     r_inst = getinstancerepr(rtyper, classdef)
     pyobj = r_inst.convert_const(rpython_obj)
     return lltype.cast_pointer(PyObjPtr, pyobj)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:rcpy.py

示例15: materialize

 def materialize(rgenop, boxes):
     s = lltype.malloc(TYPE)
     i = 0
     for desc in descs:
         v = rvalue.ll_getvalue(boxes[i], desc.RESTYPE)
         tgt = lltype.cast_pointer(desc.PTRTYPE, s)
         setattr(tgt, desc.fieldname, v)
         i = i + 1
     return rgenop.genconst(s)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:rcontainer.py


注:本文中的pypy.rpython.lltypesystem.lltype.cast_pointer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。