本文整理汇总了Python中pypy.rlib.rgc.can_move函数的典型用法代码示例。如果您正苦于以下问题:Python can_move函数的具体用法?Python can_move怎么用?Python can_move使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了can_move函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: func
def func():
from pypy.rlib import rgc
a = rgc.malloc_nonmovable(TP, 3)
if a:
assert not rgc.can_move(a)
return 0
return 1
示例2: func
def func():
#try:
a = rgc.malloc_nonmovable(TP, 3, zero=True)
rgc.collect()
if a:
assert not rgc.can_move(a)
return 0
return 1
示例3: func
def func():
try:
from pypy.rlib import rgc
a = rgc.malloc_nonmovable(TP, 3)
rgc.collect()
if a:
assert not rgc.can_move(a)
return 0
return 1
except Exception, e:
return 2
示例4: rewrite_assembler
def rewrite_assembler(self, cpu, operations):
# Perform two kinds of rewrites in parallel:
#
# - Add COND_CALLs to the write barrier before SETFIELD_GC and
# SETARRAYITEM_GC operations.
#
# - Remove all uses of ConstPtrs away from the assembler.
# Idea: when running on a moving GC, we can't (easily) encode
# the ConstPtrs in the assembler, because they can move at any
# point in time. Instead, we store them in 'gcrefs.list', a GC
# but nonmovable list; and here, we modify 'operations' to
# replace direct usage of ConstPtr with a BoxPtr loaded by a
# GETFIELD_RAW from the array 'gcrefs.list'.
#
newops = []
for op in operations:
if op.opnum == rop.DEBUG_MERGE_POINT:
continue
# ---------- replace ConstPtrs with GETFIELD_RAW ----------
# xxx some performance issue here
for i in range(len(op.args)):
v = op.args[i]
if isinstance(v, ConstPtr) and bool(v.value):
addr = self.gcrefs.get_address_of_gcref(v.value)
# ^^^even for non-movable objects, to record their presence
if rgc.can_move(v.value):
box = BoxPtr(v.value)
addr = cpu.cast_adr_to_int(addr)
newops.append(ResOperation(rop.GETFIELD_RAW,
[ConstInt(addr)], box,
self.single_gcref_descr))
op.args[i] = box
# ---------- write barrier for SETFIELD_GC ----------
if op.opnum == rop.SETFIELD_GC:
v = op.args[1]
if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
bool(v.value)): # store a non-NULL
self._gen_write_barrier(newops, op.args[0], v)
op = ResOperation(rop.SETFIELD_RAW, op.args, None,
descr=op.descr)
# ---------- write barrier for SETARRAYITEM_GC ----------
if op.opnum == rop.SETARRAYITEM_GC:
v = op.args[2]
if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
bool(v.value)): # store a non-NULL
self._gen_write_barrier(newops, op.args[0], v)
op = ResOperation(rop.SETARRAYITEM_RAW, op.args, None,
descr=op.descr)
# ----------
newops.append(op)
del operations[:]
operations.extend(newops)
示例5: convert_to_imm
def convert_to_imm(self, c):
if isinstance(c, ConstInt):
return imm(c.value)
elif isinstance(c, ConstPtr):
if we_are_translated() and c.value and rgc.can_move(c.value):
print "convert_to_imm: ConstPtr needs special care"
raise AssertionError
return imm(rffi.cast(lltype.Signed, c.value))
elif isinstance(c, ConstAddr):
return imm(ll2ctypes.cast_adr_to_int(c.value))
else:
print "convert_to_imm: got a %s" % c
raise AssertionError
示例6: get_nonmovingbuffer
def get_nonmovingbuffer(data):
"""
Either returns a non-moving copy or performs neccessary pointer
arithmetic to return a pointer to the characters of a string if the
string is already nonmovable. Must be followed by a
free_nonmovingbuffer call.
"""
if rgc.can_move(data):
count = len(data)
buf = lltype.malloc(TYPEP.TO, count, flavor="raw")
for i in range(count):
buf[i] = data[i]
return buf
else:
data_start = cast_ptr_to_adr(llstrtype(data)) + offsetof(STRTYPE, "chars") + itemoffsetof(STRTYPE.chars, 0)
return cast(TYPEP, data_start)
示例7: f
def f(i):
if i:
return rgc.can_move(lltype.malloc(T0))
else:
return rgc.can_move(lltype.malloc(T1, 1))
示例9: func
def func():
a = rgc.malloc_nonmovable(TP, 3)
if a:
assert not rgc.can_move(a)
return 0
return 1