def conv(n): if not isinstance(n, int): if isinstance(n, tuple): n = tuple(map(conv, n)) else: n = convert_offset_to_int(n) return n
def _store(self, fmt, *values): # XXX annoyance: suddenly a Symbolic changes into a Signed?! from pypy.rpython.memory.lltypelayout import convert_offset_to_int if len(values) == 1 and isinstance(values[0], llmemory.AddressOffset): values = [convert_offset_to_int(values[0])] elif len(values) == 1 and isinstance(values[0], ComputedIntSymbolic): values = [values[0].compute_fn()] simulator.setstruct(fmt, self.intaddress, *values)
def __sub__(self, other): if isinstance(other, int): return _address(self.intaddress - other) elif isinstance(other, llmemory.AddressOffset): return _address(self.intaddress - convert_offset_to_int(other)) else: assert isinstance(other, _address) return self.intaddress - other.intaddress
def guess_size_obj(obj): TYPE = typeOf(obj) ptr = _ptr(Ptr(TYPE), obj) if TYPE._is_varsize(): arrayfld = getattr(TYPE, '_arrayfld', None) if arrayfld: length = len(getattr(ptr, arrayfld)) else: try: length = len(ptr) except TypeError: print "couldn't find size of", ptr return 0 else: length = None return convert_offset_to_int(llmemory.sizeof(TYPE, length))
def raw_malloc_usage(size): if isinstance(size, AddressOffset): # ouah from pypy.rpython.memory.lltypelayout import convert_offset_to_int size = convert_offset_to_int(size) return size
def convert1(symb): if isinstance(symb, int): return symb return convert_offset_to_int(symb)
def conv(n): if not isinstance(n, int): n = convert_offset_to_int(n) return n
def conv(n): if not isinstance(n, int) and not isinstance(n, str): n = convert_offset_to_int(n) return n
def convert_to(self, offset): from pypy.rpython.memory.lltypelayout import convert_offset_to_int # XXX same annoyance as in _store if isinstance(offset, llmemory.AddressOffset): return convert_offset_to_int(offset) return int(offset)
def __add__(self, offset): if isinstance(offset, int): return _address(self.intaddress + offset) else: assert isinstance(offset, llmemory.AddressOffset) return _address(self.intaddress + convert_offset_to_int(offset))
def get_real_value(val_or_ptr): if isinstance(val_or_ptr, llmemory.AddressOffset): return lltypelayout.convert_offset_to_int(val_or_ptr) return val_or_ptr