本文整理汇总了Python中pypy.rpython.lltypesystem.llmemory.itemoffsetof函数的典型用法代码示例。如果您正苦于以下问题:Python itemoffsetof函数的具体用法?Python itemoffsetof怎么用?Python itemoffsetof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了itemoffsetof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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