本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.cast_pointer函数的典型用法代码示例。如果您正苦于以下问题:Python cast_pointer函数的具体用法?Python cast_pointer怎么用?Python cast_pointer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_pointer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: touch_update
def touch_update(strucref):
struc = lltype.cast_opaque_ptr(TOPPTR, strucref)
vable_rti = struc.vable_rti
vable_rti = cast_base_ptr_to_instance(VirtualizableRTI, vable_rti)
vable_rti.touch(struc.vable_base)
vable_base = struc.vable_base
j = -1
for fielddesc, _ in redirected_fielddescs:
j += 1
if fielddesc.canbevirtual and fielddesc.gcref:
if vable_rti.is_field_virtual(vable_base, j):
continue
v = vable_rti.read_field(fielddesc, vable_base, j)
tgt = lltype.cast_pointer(fielddesc.PTRTYPE, struc)
setattr(tgt, fielddesc.fieldname, v)
ACCESSPTR = TOPPTR.TO.vable_access
struc.vable_access = lltype.cast_pointer(ACCESSPTR, access_touched)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:18,代码来源:rvirtualizable.py
示例17: genconst
def genconst(llvalue):
T = lltype.typeOf(llvalue)
T1 = lltype.erasedType(T)
if T1 != T:
llvalue = lltype.cast_pointer(T1, llvalue)
v = flowmodel.Constant(llvalue)
v.concretetype = T1
if v.concretetype == lltype.Void: # XXX genconst should not really be used for Void constants
assert not isinstance(llvalue, str) and not isinstance(llvalue, lltype.LowLevelType)
return to_opaque_object(v)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:llimpl.py
示例18: test_cast_simple_widening
def test_cast_simple_widening():
S2 = lltype.Struct("s2", ('a', lltype.Signed))
S1 = lltype.Struct("s1", ('sub1', S2), ('sub2', S2))
p1 = malloc(S1, immortal=True)
p2 = p1.sub1
p3 = p2
p4 = cast_pointer(lltype.Ptr(S1), p3)
assert p4 == p1
SUnrelated = lltype.Struct("unrelated")
py.test.raises(TypeError, "cast_pointer(lltype.Ptr(SUnrelated), p3)")
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:test_lltypesimulation.py
示例19: test_more_fakeaddress_equality
def test_more_fakeaddress_equality():
S = lltype.GcStruct('S', ('x', lltype.Signed))
T = lltype.GcStruct('T', ('s', S))
t = lltype.malloc(T)
t.s.x = 1
s = lltype.cast_pointer(lltype.Ptr(S), t)
a_t, a_s = map(cast_ptr_to_adr, [s, t])
assert a_t == a_s
开发者ID:ieure,项目名称:pypy,代码行数:10,代码来源:test_llmemory.py
示例20: encode_type_shape
def encode_type_shape(builder, info, TYPE, index):
"""Encode the shape of the TYPE into the TYPE_INFO structure 'info'."""
offsets = offsets_to_gc_pointers(TYPE)
infobits = index
info.ofstoptrs = builder.offsets2table(offsets, TYPE)
#
kind_and_fptr = builder.special_funcptr_for_type(TYPE)
if kind_and_fptr is not None:
kind, fptr = kind_and_fptr
info.finalizer_or_customtrace = fptr
if kind == "finalizer":
infobits |= T_HAS_FINALIZER
elif kind == "light_finalizer":
infobits |= T_HAS_FINALIZER | T_HAS_LIGHTWEIGHT_FINALIZER
elif kind == "custom_trace":
infobits |= T_HAS_CUSTOM_TRACE
else:
assert 0, kind
#
if not TYPE._is_varsize():
info.fixedsize = llarena.round_up_for_allocation(llmemory.sizeof(TYPE), builder.GCClass.object_minimal_size)
# note about round_up_for_allocation(): in the 'info' table
# we put a rounded-up size only for fixed-size objects. For
# varsize ones, the GC must anyway compute the size at run-time
# and round up that result.
else:
infobits |= T_IS_VARSIZE
varinfo = lltype.cast_pointer(GCData.VARSIZE_TYPE_INFO_PTR, info)
info.fixedsize = llmemory.sizeof(TYPE, 0)
if isinstance(TYPE, lltype.Struct):
ARRAY = TYPE._flds[TYPE._arrayfld]
ofs1 = llmemory.offsetof(TYPE, TYPE._arrayfld)
varinfo.ofstolength = ofs1 + llmemory.ArrayLengthOffset(ARRAY)
varinfo.ofstovar = ofs1 + llmemory.itemoffsetof(ARRAY, 0)
else:
assert isinstance(TYPE, lltype.GcArray)
ARRAY = TYPE
if isinstance(ARRAY.OF, lltype.Ptr) and ARRAY.OF.TO._gckind == "gc":
infobits |= T_IS_GCARRAY_OF_GCPTR
varinfo.ofstolength = llmemory.ArrayLengthOffset(ARRAY)
varinfo.ofstovar = llmemory.itemoffsetof(TYPE, 0)
assert isinstance(ARRAY, lltype.Array)
if ARRAY.OF != lltype.Void:
offsets = offsets_to_gc_pointers(ARRAY.OF)
else:
offsets = ()
if len(offsets) > 0:
infobits |= T_HAS_GCPTR_IN_VARSIZE
varinfo.varofstoptrs = builder.offsets2table(offsets, ARRAY.OF)
varinfo.varitemsize = llmemory.sizeof(ARRAY.OF)
if builder.is_weakref_type(TYPE):
infobits |= T_IS_WEAKREF
if is_subclass_of_object(TYPE):
infobits |= T_IS_RPYTHON_INSTANCE
info.infobits = infobits | T_KEY_VALUE
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:55,代码来源:gctypelayout.py
注:本文中的pypy.rpython.lltypesystem.lltype.cast_pointer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论