本文整理汇总了Python中pypy.rlib.rarithmetic.ovfcheck函数的典型用法代码示例。如果您正苦于以下问题:Python ovfcheck函数的具体用法?Python ovfcheck怎么用?Python ovfcheck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ovfcheck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ll_join
def ll_join(s, length, items):
s_chars = s.chars
s_len = len(s_chars)
num_items = length
if num_items == 0:
return s.empty()
itemslen = 0
i = 0
while i < num_items:
try:
itemslen = ovfcheck(itemslen + len(items[i].chars))
except OverflowError:
raise MemoryError
i += 1
try:
seplen = ovfcheck(s_len * (num_items - 1))
except OverflowError:
raise MemoryError
# a single '+' at the end is allowed to overflow: it gets
# a negative result, and the gc will complain
result = s.malloc(itemslen + seplen)
res_index = len(items[0].chars)
s.copy_contents(items[0], result, 0, 0, res_index)
i = 1
while i < num_items:
s.copy_contents(s, result, 0, res_index, s_len)
res_index += s_len
lgt = len(items[i].chars)
s.copy_contents(items[i], result, 0, res_index, lgt)
res_index += lgt
i += 1
return result
示例2: unicode_expandtabs__Unicode_ANY
def unicode_expandtabs__Unicode_ANY(space, w_self, w_tabsize):
self = w_self._value
tabsize = space.int_w(w_tabsize)
parts = _split_with(self, u'\t')
result = [parts[0]]
prevsize = 0
for ch in parts[0]:
prevsize += 1
if ch == u"\n" or ch == u"\r":
prevsize = 0
totalsize = prevsize
for i in range(1, len(parts)):
pad = tabsize - prevsize % tabsize
nextpart = parts[i]
try:
totalsize = ovfcheck(totalsize + pad)
totalsize = ovfcheck(totalsize + len(nextpart))
result.append(u' ' * pad)
except OverflowError:
raise OperationError(space.w_OverflowError, space.wrap('new string is too long'))
result.append(nextpart)
prevsize = 0
for ch in nextpart:
prevsize += 1
if ch in (u"\n", u"\r"):
prevsize = 0
return space.wrap(u''.join(result))
示例3: malloc_varsize_clear
def malloc_varsize_clear(self, typeid16, length, size, itemsize,
offset_to_length, can_collect):
if can_collect:
self.maybe_collect()
size_gc_header = self.gcheaderbuilder.size_gc_header
try:
fixsize = size_gc_header + size
varsize = ovfcheck(itemsize * length)
tot_size = ovfcheck(fixsize + varsize)
usage = raw_malloc_usage(tot_size)
bytes_malloced = ovfcheck(self.bytes_malloced+usage)
ovfcheck(self.heap_usage + bytes_malloced)
except OverflowError:
raise memoryError
result = raw_malloc(tot_size)
if not result:
raise memoryError
raw_memclear(result, tot_size)
(result + size_gc_header + offset_to_length).signed[0] = length
hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
hdr.typeid16 = typeid16
hdr.mark = False
hdr.flags = '\x00'
hdr.next = self.malloced_objects
self.malloced_objects = hdr
self.bytes_malloced = bytes_malloced
result += size_gc_header
#llop.debug_print(lltype.Void, 'malloc_varsize length', length,
# 'typeid', typeid16,
# '->', llmemory.cast_adr_to_int(result))
self.write_malloc_statistics(typeid16, tot_size, result, True)
return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
示例4: malloc_fixedsize
def malloc_fixedsize(self, typeid16, size, can_collect,
has_finalizer=False, contains_weakptr=False):
if can_collect:
self.maybe_collect()
size_gc_header = self.gcheaderbuilder.size_gc_header
try:
tot_size = size_gc_header + size
usage = raw_malloc_usage(tot_size)
bytes_malloced = ovfcheck(self.bytes_malloced+usage)
ovfcheck(self.heap_usage + bytes_malloced)
except OverflowError:
raise memoryError
result = raw_malloc(tot_size)
if not result:
raise memoryError
hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
hdr.typeid16 = typeid16
hdr.mark = False
hdr.flags = '\x00'
if has_finalizer:
hdr.next = self.malloced_objects_with_finalizer
self.malloced_objects_with_finalizer = hdr
elif contains_weakptr:
hdr.next = self.objects_with_weak_pointers
self.objects_with_weak_pointers = hdr
else:
hdr.next = self.malloced_objects
self.malloced_objects = hdr
self.bytes_malloced = bytes_malloced
result += size_gc_header
#llop.debug_print(lltype.Void, 'malloc typeid', typeid16,
# '->', llmemory.cast_adr_to_int(result))
self.write_malloc_statistics(typeid16, tot_size, result, False)
return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
示例5: _ll_compute_size
def _ll_compute_size(length, size, itemsize):
try:
varsize = ovfcheck(itemsize * length)
tot_size = ovfcheck(size + varsize)
except OverflowError:
raise MemoryError()
return tot_size
示例6: handle_new_array
def handle_new_array(self, arraydescr, op):
v_length = op.getarg(0)
total_size = -1
if isinstance(v_length, ConstInt):
num_elem = v_length.getint()
self.known_lengths[op.result] = num_elem
try:
var_size = ovfcheck(arraydescr.itemsize * num_elem)
total_size = ovfcheck(arraydescr.basesize + var_size)
except OverflowError:
pass # total_size is still -1
elif arraydescr.itemsize == 0:
total_size = arraydescr.basesize
if (total_size >= 0 and
self.gen_malloc_nursery(total_size, op.result)):
self.gen_initialize_tid(op.result, arraydescr.tid)
self.gen_initialize_len(op.result, v_length, arraydescr.lendescr)
elif self.gc_ll_descr.kind == 'boehm':
self.gen_boehm_malloc_array(arraydescr, v_length, op.result)
else:
opnum = op.getopnum()
if opnum == rop.NEW_ARRAY:
self.gen_malloc_array(arraydescr, v_length, op.result)
elif opnum == rop.NEWSTR:
self.gen_malloc_str(v_length, op.result)
elif opnum == rop.NEWUNICODE:
self.gen_malloc_unicode(v_length, op.result)
else:
raise NotImplementedError(op.getopname())
示例7: realloc
def realloc(self, ptr, newlength, fixedsize, itemsize, lengthofs, grow):
size_gc_header = self.size_gc_header()
addr = llmemory.cast_ptr_to_adr(ptr)
tid = self.get_type_id(addr)
nonvarsize = size_gc_header + fixedsize
try:
varsize = ovfcheck(itemsize * newlength)
tot_size = ovfcheck(nonvarsize + varsize)
except OverflowError:
raise MemoryError()
oldlength = (addr + lengthofs).signed[0]
old_tot_size = size_gc_header + fixedsize + oldlength * itemsize
source_addr = addr - size_gc_header
self.gen2_resizable_objects.remove(addr)
if grow:
result = llop.raw_realloc_grow(llmemory.Address, source_addr,
old_tot_size, tot_size)
else:
result = llop.raw_realloc_shrink(llmemory.Address, source_addr,
old_tot_size, tot_size)
if not result:
self.gen2_resizable_objects.append(addr)
raise MemoryError()
if grow:
self.gen2_resizable_objects.append(result + size_gc_header)
else:
self.gen2_rawmalloced_objects.append(result + size_gc_header)
self._check_rawsize_alloced(raw_malloc_usage(tot_size) -
raw_malloc_usage(old_tot_size),
can_collect = not grow)
(result + size_gc_header + lengthofs).signed[0] = newlength
return llmemory.cast_adr_to_ptr(result + size_gc_header, llmemory.GCREF)
示例8: malloc_varsize_slowpath
def malloc_varsize_slowpath(self, typeid, length, force_nonmovable=False):
# For objects that are too large, or when the nursery is exhausted.
# In order to keep malloc_varsize_clear() as compact as possible,
# we recompute what we need in this slow path instead of passing
# it all as function arguments.
size_gc_header = self.gcheaderbuilder.size_gc_header
nonvarsize = size_gc_header + self.fixed_size(typeid)
itemsize = self.varsize_item_sizes(typeid)
offset_to_length = self.varsize_offset_to_length(typeid)
try:
varsize = ovfcheck(itemsize * length)
totalsize = ovfcheck(nonvarsize + varsize)
except OverflowError:
raise MemoryError()
if self.has_gcptr_in_varsize(typeid):
nonlarge_max = self.nonlarge_gcptrs_max
else:
nonlarge_max = self.nonlarge_max
if force_nonmovable or raw_malloc_usage(totalsize) > nonlarge_max:
result = self.malloc_varsize_marknsweep(totalsize)
flags = self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS | GCFLAG_UNVISITED
else:
result = self.malloc_varsize_collecting_nursery(totalsize)
flags = self.GCFLAGS_FOR_NEW_YOUNG_OBJECTS
self.init_gc_object(result, typeid, flags)
(result + size_gc_header + offset_to_length).signed[0] = length
return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
示例9: can_inline_malloc_varsize
def can_inline_malloc_varsize(self, arraydescr, num_elem):
assert isinstance(arraydescr, BaseArrayDescr)
basesize = arraydescr.get_base_size(self.translate_support_code)
itemsize = arraydescr.get_item_size(self.translate_support_code)
try:
size = ovfcheck(basesize + ovfcheck(itemsize * num_elem))
return size < self.max_size_of_young_obj
except OverflowError:
return False
示例10: malloc_array
def malloc_array(basesize, itemsize, ofs_length, num_elem):
try:
size = ovfcheck(basesize + ovfcheck(itemsize * num_elem))
except OverflowError:
return lltype.nullptr(llmemory.GCREF.TO)
res = self.funcptr_for_new(size)
if not res:
return res
rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[ofs_length/WORD] = num_elem
return res
示例11: malloc_array
def malloc_array(basesize, num_elem, itemsize, ofs_length):
try:
totalsize = ovfcheck(basesize + ovfcheck(itemsize * num_elem))
except OverflowError:
return lltype.nullptr(llmemory.GCREF.TO)
res = self.malloc_fn_ptr(totalsize)
if res:
arrayptr = rffi.cast(rffi.CArrayPtr(lltype.Signed), res)
arrayptr[ofs_length/WORD] = num_elem
return res
示例12: f
def f(x):
try:
a = ovfcheck(x + 50)
except OverflowError:
return 0
try:
a += ovfcheck(100 + x)
except OverflowError:
return 1
return a
示例13: ll_malloc_varsize_no_length
def ll_malloc_varsize_no_length(length, size, itemsize):
try:
varsize = ovfcheck(itemsize * length)
tot_size = ovfcheck(size + varsize)
except OverflowError:
raise memoryError
result = llop.boehm_malloc(llmemory.Address, tot_size)
if not result:
raise memoryError
return result
示例14: ll_malloc_varsize_no_length
def ll_malloc_varsize_no_length(length, size, itemsize):
try:
fixsize = gc_header_offset + size
varsize = ovfcheck(itemsize * length)
tot_size = ovfcheck(fixsize + varsize)
except OverflowError:
raise MemoryError()
result = mh._ll_malloc_fixedsize(tot_size)
llmemory.raw_memclear(result, tot_size)
result += gc_header_offset
return result
示例15: add
def add(self, offset):
res = self.clone()
try:
res.lower = ovfcheck(res.lower + offset)
except OverflowError:
res.has_lower = False
try:
res.upper = ovfcheck(res.upper + offset)
except OverflowError:
res.has_upper = False
return res