本文整理汇总了Python中pypy.rlib.objectmodel.keepalive_until_here函数的典型用法代码示例。如果您正苦于以下问题:Python keepalive_until_here函数的具体用法?Python keepalive_until_here怎么用?Python keepalive_until_here使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了keepalive_until_here函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ll_arraycopy
def ll_arraycopy(source, dest, source_start, dest_start, length):
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rlib.objectmodel import keepalive_until_here
# supports non-overlapping copies only
if not we_are_translated():
if source == dest:
assert (source_start + length <= dest_start or
dest_start + length <= source_start)
TP = lltype.typeOf(source).TO
assert TP == lltype.typeOf(dest).TO
if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
# perform a write barrier that copies necessary flags from
# source to dest
if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest):
# if the write barrier is not supported, copy by hand
for i in range(length):
dest[i + dest_start] = source[i + source_start]
return
source_addr = llmemory.cast_ptr_to_adr(source)
dest_addr = llmemory.cast_ptr_to_adr(dest)
cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
llmemory.sizeof(TP.OF) * source_start)
cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
llmemory.sizeof(TP.OF) * dest_start)
llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
llmemory.sizeof(TP.OF) * length)
keepalive_until_here(source)
keepalive_until_here(dest)
开发者ID:ieure,项目名称:pypy,代码行数:31,代码来源:rgc.py
示例2: ll_shrink_array
def ll_shrink_array(p, smallerlength):
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rlib.objectmodel import keepalive_until_here
if llop.shrink_array(lltype.Bool, p, smallerlength):
return p # done by the GC
# XXX we assume for now that the type of p is GcStruct containing a
# variable array, with no further pointers anywhere, and exactly one
# field in the fixed part -- like STR and UNICODE.
TP = lltype.typeOf(p).TO
newp = lltype.malloc(TP, smallerlength)
assert len(TP._names) == 2
field = getattr(p, TP._names[0])
setattr(newp, TP._names[0], field)
ARRAY = getattr(TP, TP._arrayfld)
offset = (llmemory.offsetof(TP, TP._arrayfld) +
llmemory.itemoffsetof(ARRAY, 0))
source_addr = llmemory.cast_ptr_to_adr(p) + offset
dest_addr = llmemory.cast_ptr_to_adr(newp) + offset
llmemory.raw_memcopy(source_addr, dest_addr,
llmemory.sizeof(ARRAY.OF) * smallerlength)
keepalive_until_here(p)
keepalive_until_here(newp)
return newp
开发者ID:ieure,项目名称:pypy,代码行数:28,代码来源:rgc.py
示例3: test_callback
def test_callback(self):
slong = cast_type_to_ffitype(rffi.LONG)
libc = self.get_libc()
qsort = libc.getpointer("qsort", [ffi_type_pointer, slong, slong, ffi_type_pointer], ffi_type_void)
def callback(ll_args, ll_res, stuff):
p_a1 = rffi.cast(rffi.VOIDPP, ll_args[0])[0]
p_a2 = rffi.cast(rffi.VOIDPP, ll_args[1])[0]
a1 = rffi.cast(rffi.INTP, p_a1)[0]
a2 = rffi.cast(rffi.INTP, p_a2)[0]
res = rffi.cast(rffi.INTP, ll_res)
if a1 > a2:
res[0] = rffi.cast(rffi.INT, 1)
else:
res[0] = rffi.cast(rffi.INT, -1)
ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer], ffi_type_sint, callback)
TP = rffi.CArray(rffi.INT)
to_sort = lltype.malloc(TP, 4, flavor="raw")
to_sort[0] = rffi.cast(rffi.INT, 4)
to_sort[1] = rffi.cast(rffi.INT, 3)
to_sort[2] = rffi.cast(rffi.INT, 1)
to_sort[3] = rffi.cast(rffi.INT, 2)
qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
qsort.push_arg(rffi.sizeof(rffi.INT))
qsort.push_arg(4)
qsort.push_arg(ptr.ll_closure)
qsort.call(lltype.Void)
assert [rffi.cast(lltype.Signed, to_sort[i]) for i in range(4)] == [1, 2, 3, 4]
lltype.free(to_sort, flavor="raw")
keepalive_until_here(ptr) # <= this test is not translated, but don't
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:32,代码来源:test_clibffi.py
示例4: f
def f(i):
c = g()
c.y
if i:
n = c.z1
else:
n = c.z2
objectmodel.keepalive_until_here(c, n)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_simplify.py
示例5: fn1
def fn1(x, y):
if x > 0:
t = x+y, x-y
else:
t = x-y, x+y
s, d = t
keepalive_until_here(t)
return s*d
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:test_malloc.py
示例6: copy_string_contents
def copy_string_contents(src, dst, srcstart, dststart, length):
assert srcstart >= 0
assert dststart >= 0
assert length >= 0
src = llmemory.cast_ptr_to_adr(src) + _str_ofs(srcstart)
dst = llmemory.cast_ptr_to_adr(dst) + _str_ofs(dststart)
llmemory.raw_memcopy(src, dst, llmemory.sizeof(CHAR_TP) * length)
keepalive_until_here(src)
keepalive_until_here(dst)
开发者ID:craigkerstiens,项目名称:pypy,代码行数:9,代码来源:rstr.py
示例7: start_all_threads
def start_all_threads():
s = allocate_stuff()
ident1 = new_thread()
ident2 = new_thread()
ident3 = new_thread()
ident4 = new_thread()
ident5 = new_thread()
# wait for 4 more seconds, which should be plenty of time
time.sleep(4)
keepalive_until_here(s)
开发者ID:ieure,项目名称:pypy,代码行数:10,代码来源:test_standalone.py
示例8: ll_function
def ll_function(flag):
t = lltype.malloc(T)
t.s.n = 3
t.s1.n = 3
if flag:
s = t.s
else:
s = t.s1
objectmodel.keepalive_until_here(t)
return s, t
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:test_annotator.py
示例9: myfunc
def myfunc():
b = B()
b.keep = A()
b.data = llmemory.cast_adr_to_ptr(b.keep.addr, PARRAY)
b.data[0] = 42
ptr = b.data
# normally 'b' could go away as early as here, which would free
# the memory held by the instance of A in b.keep...
res = ptr[0]
# ...so we explicitly keep 'b' alive until here
objectmodel.keepalive_until_here(b)
return res
开发者ID:antoine1fr,项目名称:pygirl,代码行数:12,代码来源:test_malloc.py
示例10: _digest
def _digest(self, space):
copy = self.copy(space)
ctx = copy.ctx
digest_size = self._digest_size()
digest = lltype.malloc(rffi.CCHARP.TO, digest_size, flavor='raw')
try:
ropenssl.EVP_DigestFinal(ctx, digest, None)
return rffi.charpsize2str(digest, digest_size)
finally:
keepalive_until_here(copy)
lltype.free(digest, flavor='raw')
开发者ID:gorakhargosh,项目名称:pypy,代码行数:12,代码来源:interp_hashlib.py
示例11: f
def f(n):
states = []
while n > 0:
mydriver.jit_merge_point(n=n, states=states)
state = State()
states.append(state)
x = X(state)
do_stuff()
state.num *= 1000
do_stuff()
keepalive_until_here(x)
n -= 1
return states
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_del.py
示例12: f
def f():
x = lltype.malloc(S)
x.x = 10
y = lltype.malloc(S)
y.x = 20
z = x
llop.gc_x_become(lltype.Void,
llmemory.cast_ptr_to_adr(x),
llmemory.cast_ptr_to_adr(y))
# keep 'y' alive until the x_become() is finished, because in
# theory it could go away as soon as only its address is present
objectmodel.keepalive_until_here(y)
return z.x
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:13,代码来源:test_transformed_gc.py
示例13: _ll_list_resize_really
def _ll_list_resize_really(l, newsize):
"""
Ensure l.items has room for at least newsize elements, and set
l.length to newsize. Note that l.items may change, and even if
newsize is less than l.length on entry.
"""
allocated = len(l.items)
# This over-allocates proportional to the list size, making room
# for additional growth. The over-allocation is mild, but is
# enough to give linear-time amortized behavior over a long
# sequence of appends() in the presence of a poorly-performing
# system malloc().
# The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
if newsize <= 0:
ll_assert(newsize == 0, "negative list length")
l.length = 0
l.items = _ll_new_empty_item_array(typeOf(l).TO)
return
else:
if newsize < 9:
some = 3
else:
some = 6
some += newsize >> 3
try:
new_allocated = ovfcheck(newsize + some)
except OverflowError:
raise MemoryError
# XXX consider to have a real realloc
items = l.items
newitems = malloc(typeOf(l).TO.items.TO, new_allocated)
before_len = l.length
if before_len < new_allocated:
p = before_len - 1
else:
p = new_allocated - 1
ITEM = typeOf(l).TO.ITEM
if isinstance(ITEM, Ptr):
while p >= 0:
newitems[p] = items[p]
items[p] = nullptr(ITEM.TO)
p -= 1
else:
source = cast_ptr_to_adr(items) + itemoffsetof(typeOf(l.items).TO, 0)
dest = cast_ptr_to_adr(newitems) + itemoffsetof(typeOf(l.items).TO, 0)
s = p + 1
raw_memcopy(source, dest, sizeof(ITEM) * s)
keepalive_until_here(items)
l.length = newsize
l.items = newitems
开发者ID:enyst,项目名称:plexnet,代码行数:51,代码来源:rlist.py
示例14: free_nonmovingbuffer
def free_nonmovingbuffer(data, buf):
"""
Either free a non-moving buffer or keep the original storage alive.
"""
# We cannot rely on rgc.can_move(data) here, because its result
# might have changed since get_nonmovingbuffer(). Instead we check
# if 'buf' points inside 'data'. This is only possible if we
# followed the 2nd case in get_nonmovingbuffer(); in the first case,
# 'buf' points to its own raw-malloced memory.
data = llstrtype(data)
data_start = cast_ptr_to_adr(data) + offsetof(STRTYPE, "chars") + itemoffsetof(STRTYPE.chars, 0)
followed_2nd_path = buf == cast(TYPEP, data_start)
keepalive_until_here(data)
if not followed_2nd_path:
lltype.free(buf, flavor="raw")
开发者ID:are-prabhu,项目名称:pypy,代码行数:15,代码来源:rffi.py
示例15: str_from_buffer
def str_from_buffer(raw_buf, gc_buf, allocated_size, needed_size):
"""
Converts from a pair returned by alloc_buffer to a high-level string.
The returned string will be truncated to needed_size.
"""
assert allocated_size >= needed_size
if gc_buf and (allocated_size == needed_size):
return hlstrtype(gc_buf)
new_buf = lltype.malloc(STRTYPE, needed_size)
str_chars_offset = offsetof(STRTYPE, "chars") + itemoffsetof(STRTYPE.chars, 0)
if gc_buf:
src = cast_ptr_to_adr(gc_buf) + str_chars_offset
else:
src = cast_ptr_to_adr(raw_buf) + itemoffsetof(TYPEP.TO, 0)
dest = cast_ptr_to_adr(new_buf) + str_chars_offset
raw_memcopy(src, dest, llmemory.sizeof(ll_char_type) * needed_size)
keepalive_until_here(gc_buf)
keepalive_until_here(new_buf)
return hlstrtype(new_buf)
开发者ID:are-prabhu,项目名称:pypy,代码行数:21,代码来源:rffi.py
示例16: fn
def fn(n):
keepalive = []
weakrefs = []
a = None
for i in range(n):
if i & 1 == 0:
a = A()
a.index = i
assert a is not None
weakrefs.append(weakref.ref(a))
if i % 7 == 6:
keepalive.append(a)
rgc.collect()
count_free = 0
for i in range(n):
a = weakrefs[i]()
if i % 7 == 6:
assert a is not None
if a is not None:
assert a.index == i & ~1
else:
count_free += 1
keepalive_until_here(keepalive)
return count_free
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:24,代码来源:test_boehm.py
示例17: f
def f():
libc = CDLL(get_libc_name())
qsort = libc.getpointer('qsort', [ffi_type_pointer, ffi_size_t,
ffi_size_t, ffi_type_pointer],
ffi_type_void)
ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
ffi_type_sint, callback)
TP = rffi.CArray(rffi.LONG)
to_sort = lltype.malloc(TP, 4, flavor='raw')
to_sort[0] = 4
to_sort[1] = 3
to_sort[2] = 1
to_sort[3] = 2
qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
qsort.push_arg(rffi.cast(rffi.SIZE_T, 4))
qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(rffi.LONG)))
qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
qsort.call(lltype.Void)
result = [to_sort[i] for i in range(4)] == [1,2,3,4]
lltype.free(to_sort, flavor='raw')
keepalive_until_here(ptr)
return int(result)
开发者ID:pombredanne,项目名称:pypy,代码行数:24,代码来源:test_newgc.py
示例18: fn
def fn():
s = lltype.malloc(S)
s.u = lltype.malloc(U)
s.u.next = lltype.malloc(U)
s.u.next.next = lltype.malloc(U)
a = lltype.malloc(A, 1000)
s2 = lltype.malloc(S)
#
fd1 = os.open(filename1, os.O_WRONLY | os.O_CREAT, 0666)
fd2 = os.open(filename2, os.O_WRONLY | os.O_CREAT, 0666)
rgc.dump_rpy_heap(fd1)
rgc.dump_rpy_heap(fd2) # try twice in a row
keepalive_until_here(s2)
keepalive_until_here(s)
keepalive_until_here(a)
os.close(fd1)
os.close(fd2)
return 0
开发者ID:pombredanne,项目名称:pypy,代码行数:18,代码来源:test_newgc.py
示例19: virtual_ref_finish
def virtual_ref_finish(vref, x):
"""See docstring in virtual_ref(x)"""
keepalive_until_here(x) # otherwise the whole function call is removed
_virtual_ref_finish(vref, x)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:4,代码来源:jit.py
示例20: assert_green
def assert_green(value):
"""Very strong assert: checks that 'value' is a green
(a JIT compile-time constant)."""
keepalive_until_here(value)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:4,代码来源:jit.py
注:本文中的pypy.rlib.objectmodel.keepalive_until_here函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论