Skip to content
Permalink
Browse files

fix Object#inspect, never show negative values

  • Loading branch information
alex committed Jun 27, 2013
1 parent 81c4205 commit b3df5399d8b046fdf844c9f1cc4e08a8952de974
Showing with 26 additions and 4 deletions.
  1. +4 −1 tests/objects/test_objectobject.py
  2. +22 −3 topaz/objspace.py
@@ -1,3 +1,5 @@
import struct

from topaz.objects.intobject import W_FixnumObject
from topaz.objects.methodobject import W_MethodObject

@@ -222,7 +224,8 @@ def test_to_s(self, space):
return obj.to_s, obj.object_id
""")
s, oid = self.unwrap(space, w_res)
assert s == "#<Object:0x%x>" % oid
format = "%%0%dx" % (2 * struct.calcsize("P"))
assert s == ("#<Object:0x%s>" % format) % oid

def test_inspect(self, space):
w_res = space.execute("""
@@ -7,10 +7,11 @@

from rpython.rlib import jit, rpath, types
from rpython.rlib.cache import Cache
from rpython.rlib.objectmodel import specialize
from rpython.rlib.objectmodel import specialize, compute_unique_id
from rpython.rlib.signature import signature
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.rbigint import rbigint
from rpython.rtyper.lltypesystem import llmemory, rffi

from rply.errors import ParsingError

@@ -772,10 +773,28 @@ def infect(self, w_dest, w_src, taint=True, untrust=True, freeze=False):
if freeze and self.is_true(w_src.get_flag(self, "frozen?")):
w_dest.set_flag(self, "frozen?")

def getaddrstring(self, w_obj):
w_id = self.newint_or_bigint(compute_unique_id(w_obj))
w_4 = self.newint(4)
w_0x0F = self.newint(0x0F)
i = 2 * rffi.sizeof(llmemory.Address)
addrstring = [" "] * i
while True:
n = self.int_w(self.send(w_id, "&", [w_0x0F]))
n += ord("0")
if n > ord("9"):
n += (ord("a") - ord("9") - 1)
i -= 1
addrstring[i] = chr(n)
if i == 0:
break
w_id = self.send(w_id, ">>", [w_4])
return "".join(addrstring)

def any_to_s(self, w_obj):
return "#<%s:0x%x>" % (
return "#<%s:0x%s>" % (
self.obj_to_s(self.getnonsingletonclass(w_obj)),
self.int_w(self.send(w_obj, "__id__"))
self.getaddrstring(w_obj)
)

def obj_to_s(self, w_obj):

0 comments on commit b3df539

Please sign in to comment.