本文整理汇总了Python中pypy.rpython.lltypesystem.llmemory.itemoffsetof函数的典型用法代码示例。如果您正苦于以下问题:Python itemoffsetof函数的具体用法?Python itemoffsetof怎么用?Python itemoffsetof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了itemoffsetof函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: encode_type_shape
def encode_type_shape(builder, info, TYPE):
"""Encode the shape of the TYPE into the TYPE_INFO structure 'info'."""
offsets = offsets_to_gc_pointers(TYPE)
info.ofstoptrs = builder.offsets2table(offsets, TYPE)
info.finalizer = builder.make_finalizer_funcptr_for_type(TYPE)
info.weakptrofs = weakpointer_offset(TYPE)
if not TYPE._is_varsize():
#info.isvarsize = False
#info.gcptrinvarsize = False
info.fixedsize = llarena.round_up_for_allocation(
llmemory.sizeof(TYPE))
info.ofstolength = -1
# 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:
#info.isvarsize = True
info.fixedsize = llmemory.sizeof(TYPE, 0)
if isinstance(TYPE, lltype.Struct):
ARRAY = TYPE._flds[TYPE._arrayfld]
ofs1 = llmemory.offsetof(TYPE, TYPE._arrayfld)
info.ofstolength = ofs1 + llmemory.ArrayLengthOffset(ARRAY)
info.ofstovar = ofs1 + llmemory.itemoffsetof(ARRAY, 0)
else:
ARRAY = TYPE
info.ofstolength = llmemory.ArrayLengthOffset(ARRAY)
info.ofstovar = llmemory.itemoffsetof(TYPE, 0)
assert isinstance(ARRAY, lltype.Array)
if ARRAY.OF != lltype.Void:
offsets = offsets_to_gc_pointers(ARRAY.OF)
else:
offsets = ()
info.varofstoptrs = builder.offsets2table(offsets, ARRAY.OF)
info.varitemsize = llmemory.sizeof(ARRAY.OF)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:35,代码来源:gctypelayout.py
示例2: 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
示例3: gc_pointers_inside
def gc_pointers_inside(v, adr, mutable_only=False):
t = lltype.typeOf(v)
if isinstance(t, lltype.Struct):
skip = ()
if mutable_only:
if t._hints.get("immutable"):
return
if "immutable_fields" in t._hints:
skip = t._hints["immutable_fields"].all_immutable_fields()
for n, t2 in t._flds.iteritems():
if isinstance(t2, lltype.Ptr) and t2.TO._gckind == "gc":
if n not in skip:
yield adr + llmemory.offsetof(t, n)
elif isinstance(t2, (lltype.Array, lltype.Struct)):
for a in gc_pointers_inside(getattr(v, n), adr + llmemory.offsetof(t, n), mutable_only):
yield a
elif isinstance(t, lltype.Array):
if mutable_only and t._hints.get("immutable"):
return
if isinstance(t.OF, lltype.Ptr) and t.OF.TO._gckind == "gc":
for i in range(len(v.items)):
yield adr + llmemory.itemoffsetof(t, i)
elif isinstance(t.OF, lltype.Struct):
for i in range(len(v.items)):
for a in gc_pointers_inside(v.items[i], adr + llmemory.itemoffsetof(t, i), mutable_only):
yield a
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:26,代码来源:gctypelayout.py
示例4: gc_pointers_inside
def gc_pointers_inside(v, adr, mutable_only=False):
t = lltype.typeOf(v)
if isinstance(t, lltype.Struct):
if mutable_only and t._hints.get('immutable'):
return
for n, t2 in t._flds.iteritems():
if isinstance(t2, lltype.Ptr) and t2.TO._gckind == 'gc':
yield adr + llmemory.offsetof(t, n)
elif isinstance(t2, (lltype.Array, lltype.Struct)):
for a in gc_pointers_inside(getattr(v, n),
adr + llmemory.offsetof(t, n),
mutable_only):
yield a
elif isinstance(t, lltype.Array):
if mutable_only and t._hints.get('immutable'):
return
if isinstance(t.OF, lltype.Ptr) and t.OF.TO._gckind == 'gc':
for i in range(len(v.items)):
yield adr + llmemory.itemoffsetof(t, i)
elif isinstance(t.OF, lltype.Struct):
for i in range(len(v.items)):
for a in gc_pointers_inside(v.items[i],
adr + llmemory.itemoffsetof(t, i),
mutable_only):
yield a
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:25,代码来源:gctypelayout.py
示例5: 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
示例6: _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
示例7: get_type_id
def get_type_id(self, TYPE):
try:
return self.id_of_type[TYPE]
except KeyError:
assert not self.finished_tables
assert isinstance(TYPE, (lltype.GcStruct, lltype.GcArray))
# Record the new type_id description as a small dict for now.
# It will be turned into a Struct("type_info") in finish()
type_id = len(self.type_info_list)
info = {}
self.type_info_list.append(info)
self.id_of_type[TYPE] = type_id
offsets = offsets_to_gc_pointers(TYPE)
info["ofstoptrs"] = self.offsets2table(offsets, TYPE)
info["finalyzer"] = self.finalizer_funcptr_for_type(TYPE)
if not TYPE._is_varsize():
info["isvarsize"] = False
info["fixedsize"] = llmemory.sizeof(TYPE)
info["ofstolength"] = -1
else:
info["isvarsize"] = True
info["fixedsize"] = llmemory.sizeof(TYPE, 0)
if isinstance(TYPE, lltype.Struct):
ARRAY = TYPE._flds[TYPE._arrayfld]
ofs1 = llmemory.offsetof(TYPE, TYPE._arrayfld)
info["ofstolength"] = ofs1 + llmemory.ArrayLengthOffset(ARRAY)
if ARRAY.OF != lltype.Void:
info["ofstovar"] = ofs1 + llmemory.itemoffsetof(ARRAY, 0)
else:
info["fixedsize"] = ofs1 + llmemory.sizeof(lltype.Signed)
if ARRAY._hints.get('isrpystring'):
info["fixedsize"] = llmemory.sizeof(TYPE, 1)
else:
ARRAY = TYPE
info["ofstolength"] = llmemory.ArrayLengthOffset(ARRAY)
if ARRAY.OF != lltype.Void:
info["ofstovar"] = llmemory.itemoffsetof(TYPE, 0)
else:
info["fixedsize"] = llmemory.ArrayLengthOffset(ARRAY) + llmemory.sizeof(lltype.Signed)
assert isinstance(ARRAY, lltype.Array)
if ARRAY.OF != lltype.Void:
offsets = offsets_to_gc_pointers(ARRAY.OF)
info["varofstoptrs"] = self.offsets2table(offsets, ARRAY.OF)
info["varitemsize"] = llmemory.sizeof(ARRAY.OF)
else:
info["varofstoptrs"] = self.offsets2table((), lltype.Void)
info["varitemsize"] = llmemory.sizeof(ARRAY.OF)
return type_id
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:48,代码来源:framework.py
示例8: 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
示例9: _gct_resize_buffer_no_realloc
def _gct_resize_buffer_no_realloc(self, hop, v_lgt):
op = hop.spaceop
meth = self.gct_fv_gc_malloc_varsize
flags = {'flavor':'gc', 'varsize': True, 'keep_current_args': True}
self.varsize_malloc_helper(hop, flags, meth, [])
# fish resvar
v_newbuf = hop.llops[-1].result
v_src = op.args[0]
TYPE = v_src.concretetype.TO
c_fldname = rmodel.inputconst(lltype.Void, TYPE._arrayfld)
v_adrsrc = hop.genop('cast_ptr_to_adr', [v_src],
resulttype=llmemory.Address)
v_adrnewbuf = hop.genop('cast_ptr_to_adr', [v_newbuf],
resulttype=llmemory.Address)
ofs = (llmemory.offsetof(TYPE, TYPE._arrayfld) +
llmemory.itemoffsetof(getattr(TYPE, TYPE._arrayfld), 0))
v_ofs = rmodel.inputconst(lltype.Signed, ofs)
v_adrsrc = hop.genop('adr_add', [v_adrsrc, v_ofs],
resulttype=llmemory.Address)
v_adrnewbuf = hop.genop('adr_add', [v_adrnewbuf, v_ofs],
resulttype=llmemory.Address)
size = llmemory.sizeof(getattr(TYPE, TYPE._arrayfld).OF)
c_size = rmodel.inputconst(lltype.Signed, size)
v_lgtsym = hop.genop('int_mul', [c_size, v_lgt],
resulttype=lltype.Signed)
vlist = [v_adrsrc, v_adrnewbuf, v_lgtsym]
hop.genop('raw_memcopy', vlist)
开发者ID:enyst,项目名称:plexnet,代码行数:27,代码来源:transform.py
示例10: gc_pointers_inside
def gc_pointers_inside(v, adr):
t = lltype.typeOf(v)
if isinstance(t, lltype.Struct):
for n, t2 in t._flds.iteritems():
if isinstance(t2, lltype.Ptr) and t2.TO._gckind == 'gc':
yield adr + llmemory.offsetof(t, n)
elif isinstance(t2, (lltype.Array, lltype.Struct)):
for a in gc_pointers_inside(getattr(v, n), adr + llmemory.offsetof(t, n)):
yield a
elif isinstance(t, lltype.Array):
if isinstance(t.OF, lltype.Ptr) and t2._needsgc():
for i in range(len(v.items)):
yield adr + llmemory.itemoffsetof(t, i)
elif isinstance(t.OF, lltype.Struct):
for i in range(len(v.items)):
for a in gc_pointers_inside(v.items[i], adr + llmemory.itemoffsetof(t, i)):
yield a
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:framework.py
示例11: 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)
info.finalizer = builder.make_finalizer_funcptr_for_type(TYPE)
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 TYPE == WEAKREF:
infobits |= T_IS_WEAKREF
info.infobits = infobits
开发者ID:alkorzt,项目名称:pypy,代码行数:42,代码来源:gctypelayout.py
示例12: longername
def longername(a, b, size):
if 1:
baseofs = itemoffsetof(TP, 0)
onesize = sizeof(TP.OF)
size = baseofs + onesize*(size - 1)
raw_memcopy(cast_ptr_to_adr(b)+baseofs, cast_ptr_to_adr(a)+baseofs, size)
else:
a = []
for i in range(x):
a.append(i)
return 0
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:targetlbench.py
示例13: getinneraddr
def getinneraddr(self, obj, *offsets):
TYPE = lltype.typeOf(obj).TO
addr = llmemory.cast_ptr_to_adr(obj)
for o in offsets:
if isinstance(o, str):
addr += llmemory.offsetof(TYPE, o)
TYPE = getattr(TYPE, o)
else:
addr += llmemory.itemoffsetof(TYPE, o)
TYPE = TYPE.OF
return addr, TYPE
开发者ID:antoine1fr,项目名称:pygirl,代码行数:11,代码来源:llinterp.py
示例14: 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
示例15: test_sizeof_array_with_no_length
def test_sizeof_array_with_no_length():
py.test.skip("inprogress")
A = lltype.GcArray(lltype.Signed, hints={'nolength': True})
a = lltype.malloc(A, 5, zero=True)
arraysize = llmemory.itemoffsetof(A, 10)
signedsize = llmemory.sizeof(lltype.Signed)
def f():
return a[0] + arraysize-signedsize*10
fn = compile_function(f, [])
res = fn()
assert res == 0
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:12,代码来源:test_symbolic.py
示例16: test_sizeof_array_with_no_length
def test_sizeof_array_with_no_length():
A = lltype.GcArray(lltype.Signed, hints={'nolength': True})
B = lltype.Array(lltype.Signed, hints={'nolength': True})
a = lltype.malloc(A, 5, zero=True)
arraysize = llmemory.itemoffsetof(A, 10)
signedsize = llmemory.sizeof(lltype.Signed)
b_items = llmemory.ArrayItemsOffset(B)
def f():
return (a[0] + arraysize-signedsize*10) * 1000 + b_items
fn = compile_function(f, [])
res = fn()
assert res == 0
开发者ID:antoine1fr,项目名称:pygirl,代码行数:13,代码来源:test_symbolic.py
示例17: 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
示例18: alloc_buffer
def alloc_buffer(count):
"""
Returns a (raw_buffer, gc_buffer) pair, allocated with count bytes.
The raw_buffer can be safely passed to a native function which expects
it to not move. Call str_from_buffer with the returned values to get a
safe high-level string. When the garbage collector cooperates, this
allows for the process to be performed without an extra copy.
Make sure to call keep_buffer_alive_until_here on the returned values.
"""
str_chars_offset = offsetof(STRTYPE, "chars") + itemoffsetof(STRTYPE.chars, 0)
gc_buf = rgc.malloc_nonmovable(STRTYPE, count)
if gc_buf:
realbuf = cast_ptr_to_adr(gc_buf) + str_chars_offset
raw_buf = cast(TYPEP, realbuf)
return raw_buf, gc_buf
else:
raw_buf = lltype.malloc(TYPEP.TO, count, flavor="raw")
return raw_buf, lltype.nullptr(STRTYPE)
开发者ID:alkorzt,项目名称:pypy,代码行数:18,代码来源:rffi.py
示例19: test_itemoffsetof_fixedsizearray
def test_itemoffsetof_fixedsizearray():
ARRAY = lltype.FixedSizeArray(lltype.Signed, 5)
itemoffsets = [llmemory.itemoffsetof(ARRAY, i) for i in range(5)]
a = lltype.malloc(ARRAY, immortal=True)
def f():
adr = llmemory.cast_ptr_to_adr(a)
result = 0
for i in range(5):
a[i] = i + 1
for i in range(5):
result = result * 10 + (adr + itemoffsets[i]).signed[0]
for i in range(5):
(adr + itemoffsets[i]).signed[0] = i
for i in range(5):
result = 10 * result + a[i]
return result
fn = compile_function(f, [])
res = fn()
assert res == 1234501234
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:19,代码来源:test_symbolic.py
示例20: test_itemoffsetof
def test_itemoffsetof():
ARRAY = lltype.GcArray(lltype.Signed)
itemoffsets = [llmemory.itemoffsetof(ARRAY, i) for i in range(5)]
def f():
a = lltype.malloc(ARRAY, 5)
adr = llmemory.cast_ptr_to_adr(a)
result = 0
for i in range(5):
a[i] = i + 1
for i in range(5):
result = result * 10 + (adr + itemoffsets[i]).signed[0]
for i in range(5):
(adr + itemoffsets[i]).signed[0] = i
for i in range(5):
result = 10 * result + a[i]
return result
fn, t = getcompiled(f, [])
res = fn()
assert res == 1234501234
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:19,代码来源:test_symbolic.py
注:本文中的pypy.rpython.lltypesystem.llmemory.itemoffsetof函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论