本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.direct_arrayitems函数的典型用法代码示例。如果您正苦于以下问题:Python direct_arrayitems函数的具体用法?Python direct_arrayitems怎么用?Python direct_arrayitems使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了direct_arrayitems函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_convert_subarray
def test_convert_subarray(self):
A = lltype.GcArray(lltype.Signed)
a = lltype.malloc(A, 20)
inside = lltype.direct_ptradd(lltype.direct_arrayitems(a), 3)
lltype2ctypes(inside)
start = rffi.cast(lltype.Signed, lltype.direct_arrayitems(a))
inside_int = rffi.cast(lltype.Signed, inside)
assert inside_int == start+rffi.sizeof(lltype.Signed)*3
示例2: ll_build_from_size
def ll_build_from_size(ARRAY, size, _malloc):
array = ARRAY.ll_allocate(1)
array.shape[0] = size
array.strides[0] = 1
array.data = _malloc(ARRAY.data.TO, size)
array.dataptr = direct_arrayitems(array.data)
return array
示例3: get_address_of_gcref
def get_address_of_gcref(self, gcref):
assert lltype.typeOf(gcref) == llmemory.GCREF
# first look in the hashtable, using an inexact hash (fails after
# the object moves)
addr = llmemory.cast_ptr_to_adr(gcref)
hash = llmemory.cast_adr_to_int(addr)
hash -= hash >> self.HASHTABLE_BITS
hash &= self.HASHTABLE_SIZE - 1
addr_ref = self.hashtable[hash]
# the following test is safe anyway, because the addresses found
# in the hashtable are always the addresses of nonmovable stuff
# ('addr_ref' is an address inside self.list, not directly the
# address of a real moving GC object -- that's 'addr_ref.address[0]'.)
if addr_ref.address[0] == addr:
return addr_ref
# if it fails, add an entry to the list
if self.nextindex == len(self.list):
# reallocate first, increasing a bit the size every time
self.oldlists.append(self.list)
self.list = self.alloc_gcref_list(len(self.list) // 4 * 5)
self.nextindex = 0
# add it
index = self.nextindex
self.list[index] = gcref
addr_ref = lltype.direct_ptradd(lltype.direct_arrayitems(self.list),
index)
addr_ref = llmemory.cast_ptr_to_adr(addr_ref)
self.nextindex = index + 1
# record it in the hashtable
self.hashtable[hash] = addr_ref
return addr_ref
示例4: walk_roots
def walk_roots(self, collect_stack_root,
collect_static_in_prebuilt_nongc,
collect_static_in_prebuilt_gc):
gc = self.tester.gc
layoutbuilder = self.tester.layoutbuilder
if collect_static_in_prebuilt_gc:
for addrofaddr in layoutbuilder.addresses_of_static_ptrs:
if addrofaddr.address[0]:
collect_static_in_prebuilt_gc(gc, addrofaddr)
if collect_static_in_prebuilt_nongc:
for addrofaddr in layoutbuilder.addresses_of_static_ptrs_in_nongc:
if addrofaddr.address[0]:
collect_static_in_prebuilt_nongc(gc, addrofaddr)
if collect_stack_root:
stackroots = self.tester.stackroots
a = lltype.malloc(ADDR_ARRAY, len(stackroots), flavor='raw')
for i in range(len(a)):
a[i] = llmemory.cast_ptr_to_adr(stackroots[i])
a_base = lltype.direct_arrayitems(a)
for i in range(len(a)):
ai = lltype.direct_ptradd(a_base, i)
collect_stack_root(gc, llmemory.cast_ptr_to_adr(ai))
for i in range(len(a)):
PTRTYPE = lltype.typeOf(stackroots[i])
stackroots[i] = llmemory.cast_adr_to_ptr(a[i], PTRTYPE)
lltype.free(a, flavor='raw')
示例5: ll_build_from_scalar
def ll_build_from_scalar(ARRAY, value):
array = ARRAY.ll_allocate(1)
array.shape[0] = 1
array.strides[0] = 1
array.data = malloc(ARRAY.data.TO, 1)
array.dataptr = direct_arrayitems(array.data)
array.data[0] = value
return array
示例6: ref
def ref(self, arrayptr):
assert array_type_match(lltype.typeOf(arrayptr).TO, self.TYPE)
if isinstance(self.TYPE.OF, lltype.ContainerType):
# XXX this doesn't support empty arrays
o = arrayptr._obj.getitem(0)
return o._as_ptr()
else:
return lltype.direct_arrayitems(arrayptr)
示例7: ll_chararrayvalue
def ll_chararrayvalue(box):
from pypy.rpython.rctypes import rchar_p
p = box.c_data
length = rchar_p.ll_strnlen(lltype.direct_arrayitems(p), len(p))
newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
newstr.hash = 0
for i in range(length):
newstr.chars[i] = p[i]
return newstr
示例8: writeall_not_sandboxed
def writeall_not_sandboxed(fd, buf, length):
while length > 0:
size = rffi.cast(rffi.SIZE_T, length)
count = rffi.cast(lltype.Signed, ll_write_not_sandboxed(fd, buf, size))
if count <= 0:
raise IOError
length -= count
buf = lltype.direct_ptradd(lltype.direct_arrayitems(buf), count)
buf = rffi.cast(rffi.CCHARP, buf)
示例9: ll_build_alias_to_list
def ll_build_alias_to_list(ARRAY, lst):
# This should only be used for temporary calculations
size = lst.ll_length()
array = ARRAY.ll_allocate(1)
array.shape[0] = size
array.strides[0] = 1
# Well.. this doesn't work (because array.data has nolength ?)
array.data = lst.ll_items()
array.dataptr = direct_arrayitems(array.data)
return array
示例10: ll_build_from_shape
def ll_build_from_shape(ARRAY, shape):
array = ll_allocate(ARRAY, ndim)
itemsize = 1
for i in unrolling_dims:
attr = 'item%d'%i
size = getattr(shape, attr)
array.shape[i] = size
array.strides[i] = itemsize
itemsize *= size
array.data = malloc(ARRAY.data.TO, itemsize, zero=zero)
array.dataptr = direct_arrayitems(array.data)
return array
示例11: ll_build_from_list
def ll_build_from_list(ARRAY, lst):
size = lst.ll_length()
array = ARRAY.ll_allocate(1)
array.shape[0] = size
array.strides[0] = 1
array.data = malloc(ARRAY.data.TO, size)
i = 0
while i < size:
array.data[i] = lst.ll_getitem_fast(i)
i += 1
array.dataptr = direct_arrayitems(array.data)
return array
示例12: pop
def pop(self):
while self.static_current != gcdata.static_root_end:
result = self.static_current
self.static_current += sizeofaddr
if result.address[0].address[0] != llmemory.NULL:
return result.address[0]
i = self.static_roots_index
if i > 0:
i -= 1
self.static_roots_index = i
p = lltype.direct_arrayitems(gcdata.static_roots)
p = lltype.direct_ptradd(p, i)
return llmemory.cast_ptr_to_adr(p)
return llmemory.NULL
示例13: ll_build_like
def ll_build_like(ARRAY, array0):
ndim = array0.ndim
array = ARRAY.ll_allocate(ndim)
sz = ll_mul_list(array0.shape, array0.ndim)
array.data = malloc(ARRAY.data.TO, sz)
array.dataptr = direct_arrayitems(array.data)
itemsize = 1
i = ndim - 1
while i >= 0:
size = array0.shape[i]
array.shape[i] = size
array.strides[i] = itemsize
itemsize *= size
i -= 1
return array
示例14: initialize
def initialize(self):
if we_are_translated(): n = 2000
else: n = 10 # tests only
self.list = self.alloc_gcref_list(n)
self.nextindex = 0
self.oldlists = []
# A pseudo dictionary: it is fixed size, and it may contain
# random nonsense after a collection moved the objects. It is only
# used to avoid too many duplications in the GCREF_LISTs.
self.hashtable = lltype.malloc(self.HASHTABLE,
self.HASHTABLE_SIZE+1,
flavor='raw')
dummy = lltype.direct_ptradd(lltype.direct_arrayitems(self.hashtable),
self.HASHTABLE_SIZE)
dummy = llmemory.cast_ptr_to_adr(dummy)
for i in range(self.HASHTABLE_SIZE+1):
self.hashtable[i] = dummy
示例15: ll_get_view
def ll_get_view(ARRAY, ao, tpl):
array = ARRAY.ll_allocate(ndim)
dataptr = direct_arrayitems(ao.data)
src_i = 0
tgt_i = 0
for src_i, r_key in unroll_r_tuple:
if isinstance(r_key, IntegerRepr):
dataptr = direct_ptradd(dataptr, getattr(tpl, 'item%d'%src_i)*ao.strides[src_i])
elif r_key == rslice.startonly_slice_repr:
start = getattr(tpl, 'item%d'%src_i)
size = ao.shape[src_i]
if start > size:
start = size
size -= start
dataptr = direct_ptradd(dataptr, start*ao.strides[src_i])
array.shape[tgt_i] = size
array.strides[tgt_i] = ao.strides[src_i]
tgt_i += 1
elif r_key == rslice.startstop_slice_repr:
start = getattr(tpl, 'item%d'%src_i).start
stop = getattr(tpl, 'item%d'%src_i).stop
size = ao.shape[src_i]
if start > size:
start = size
dataptr = direct_ptradd(dataptr, start*ao.strides[src_i])
if stop < size:
size = stop
size -= start
if size < 0:
size = 0
array.shape[tgt_i] = size
array.strides[tgt_i] = ao.strides[src_i]
tgt_i += 1
else:
assert 0
src_i += 1
# consume the rest of ndim as if we found more slices
while tgt_i < ndim:
array.shape[tgt_i] = ao.shape[src_i]
array.strides[tgt_i] = ao.strides[src_i]
tgt_i += 1
src_i += 1
ll_assert(tgt_i == ndim, "tgt_i == ndim")
array.dataptr = dataptr
array.data = ao.data # keep a ref
return array