def g(x): check_nonneg(x-1)
def __init__(self, space, code, w_globals, outer_func): if not we_are_translated(): assert type(self) in (space.FrameClass, CPythonFrame), ( "use space.FrameClass(), not directly PyFrame()") self = hint(self, access_directly=True, fresh_virtualizable=True) assert isinstance(code, pycode.PyCode) self.pycode = code eval.Frame.__init__(self, space, w_globals) self.locals_stack_w = [None] * (code.co_nlocals + code.co_stacksize) # Symbolic stack, globals tracker and constraint stack self.locals_stack_w_s = [None] * (code.co_nlocals + code.co_stacksize) self.w_globals_s = w_globals self.valuestackdepth = code.co_nlocals self.lastblock = None make_sure_not_resized(self.locals_stack_w) check_nonneg(self.valuestackdepth) # if space.config.objspace.honor__builtins__: self.builtin = space.builtin.pick_builtin(w_globals) # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS. # class bodies only have CO_NEWLOCALS. self.initialize_frame_scopes(outer_func, code) self.f_lineno = code.co_firstlineno
def __init__(self, deque): self.space = deque.space self.deque = deque self.block = deque.rightblock self.index = deque.rightindex self.counter = deque.len self.lock = deque.getlock() check_nonneg(self.index)
def __init__(self, pattern, match_start, end, flags): # 'match_start' and 'end' must be known to be non-negative # and they must not be more than len(string). check_nonneg(match_start) check_nonneg(end) self.pattern = pattern self.match_start = match_start self.end = end self.flags = flags
def pat(self, index): check_nonneg(index) result = self.pattern[index] # Check that we only return non-negative integers from this helper. # It is possible that self.pattern contains negative integers # (see set_charset() and set_bigcharset() in rsre_char.py) # but they should not be fetched via this helper here. assert result >= 0 return result
def get_subclass_of_correct_size(space, cls, w_type): assert space.config.objspace.std.withmapdict map = w_type.terminator classes = memo_get_subclass_of_correct_size(space, cls) if SUBCLASSES_MIN_FIELDS == SUBCLASSES_MAX_FIELDS: return classes[0] size = map.size_estimate() debug.check_nonneg(size) if size < len(classes): return classes[size] else: return classes[len(classes) - 1]
def get_subclass_of_correct_size(space, cls, w_type): assert space.config.objspace.std.withmapdict map = w_type.terminator classes = memo_get_subclass_of_correct_size(space, cls) if SUBCLASSES_MIN_FIELDS == SUBCLASSES_MAX_FIELDS: return classes[0] size = map.size_estimate() debug.check_nonneg(size) if size < len(classes): return classes[size] else: return classes[len(classes)-1]
def __init__(self, space): self.space = space self.maxlen = sys.maxint self.clear() check_nonneg(self.leftindex) check_nonneg(self.rightindex) # # lightweight locking: any modification to the content of the deque # sets the lock to None. Taking an iterator sets it to a non-None # value. The iterator can check if further modifications occurred # by checking if the lock still has the same non-None value. # (In CPython, this is implemented using d->state.) self.lock = None
def __init__(self, code, nb_args, has_vararg, nb_locals, upval_descrs, consts_w, names_w, functions_w, module_w, name='#f'): self.code = code self.name = name # check_nonneg(nb_args) self.nb_args = nb_args # including the vararg. self.has_vararg = has_vararg check_nonneg(nb_locals) self.nb_locals = nb_locals # args + locals + upvals # self.upval_descrs = upval_descrs # [chr, chr, ...], from and to self.consts_w = consts_w self.names_w = names_w # a list of local var names self.functions_w = functions_w # a list of plain functions self.module_w = module_w
def run_instr(self, space, name, num_args, bytecode, frame, pc): args = () # Do not change these from * 256 to << 8, lshift has defined overflow # semantics which cause it to not propogate the nonnegative-ness. if num_args >= 1: v = ord(bytecode.code[pc]) | (ord(bytecode.code[pc + 1]) * 256) check_nonneg(v) args += (v,) pc += 2 if num_args >= 2: v = ord(bytecode.code[pc]) | (ord(bytecode.code[pc + 1]) * 256) check_nonneg(v) args += (v,) pc += 2 if num_args >= 3: raise NotImplementedError method = getattr(self, name) res = method(space, bytecode, frame, pc, *args) if res is not None: pc = res return pc
def str(self, index): check_nonneg(index) return ord(self._string[index])
def str(self, index): check_nonneg(index) return ord(self._unicodestr[index])
def f(x): assert x >= 5 check_nonneg(x)