[pypy-svn] r41577 - in pypy/dist/pypy/rpython: lltypesystem test
arigo at codespeak.net
arigo at codespeak.net
Wed Mar 28 16:06:54 CEST 2007
Author: arigo
Date: Wed Mar 28 16:06:54 2007
New Revision: 41577
Modified:
pypy/dist/pypy/rpython/lltypesystem/rclass.py
pypy/dist/pypy/rpython/lltypesystem/rstr.py
pypy/dist/pypy/rpython/test/test_rclass.py
Log:
Put the address of the object in the str() of RPython instances.
Modified: pypy/dist/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rclass.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rclass.py Wed Mar 28 16:06:54 2007
@@ -11,7 +11,7 @@
get_type_repr, rtype_new_instance
from pypy.rpython.lltypesystem.lltype import \
Ptr, Struct, GcStruct, malloc, \
- cast_pointer, castable, nullptr, \
+ cast_pointer, cast_ptr_to_int, castable, nullptr, \
RuntimeTypeInfo, getRuntimeTypeInfo, typeOf, \
Array, Char, Void, attachRuntimeTypeInfo, \
FuncType, Bool, Signed, functionptr, FuncType, PyObject
@@ -585,18 +585,24 @@
def ll_str(self, i): # doesn't work for non-gc classes!
from pypy.rpython.lltypesystem import rstr
+ from pypy.rpython.lltypesystem.ll_str import ll_int2hex
+ from pypy.rlib.rarithmetic import r_uint
if not i:
return rstr.null_str
instance = cast_pointer(OBJECTPTR, i)
+ uid = r_uint(cast_ptr_to_int(i))
nameLen = len(instance.typeptr.name)
nameString = rstr.mallocstr(nameLen-1)
i = 0
while i < nameLen - 1:
nameString.chars[i] = instance.typeptr.name[i]
i += 1
- return rstr.ll_strconcat(rstr.instance_str_prefix,
- rstr.ll_strconcat(nameString,
- rstr.instance_str_suffix))
+ res = rstr.instance_str_prefix
+ res = rstr.ll_strconcat(res, nameString)
+ res = rstr.ll_strconcat(res, rstr.instance_str_infix)
+ res = rstr.ll_strconcat(res, ll_int2hex(uid, False))
+ res = rstr.ll_strconcat(res, rstr.instance_str_suffix)
+ return res
def rtype_isinstance(self, hop):
class_repr = get_type_repr(hop.rtyper)
Modified: pypy/dist/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rstr.py Wed Mar 28 16:06:54 2007
@@ -789,7 +789,8 @@
# not that insane that a string constant is built in this file).
instance_str_prefix = string_repr.convert_const("<")
-instance_str_suffix = string_repr.convert_const(" object>")
+instance_str_infix = string_repr.convert_const(" object at 0x")
+instance_str_suffix = string_repr.convert_const(">")
null_str = string_repr.convert_const("NULL")
Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py (original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py Wed Mar 28 16:06:54 2007
@@ -667,6 +667,22 @@
t, typer, graph = self.gengraph(f, [], backendopt=True)
assert summary(graph) == {}
+ def test_instance_repr(self):
+ class FooBar(object):
+ pass
+ def f():
+ x = FooBar()
+ return id(x), str(x)
+
+ res = self.interpret(f, [])
+ xid, xstr = self.ll_unpack_tuple(res, 2)
+ xstr = self.ll_to_string(xstr)
+ print xid, xstr
+ assert 'FooBar' in xstr
+ from pypy.rlib.rarithmetic import r_uint
+ expected = hex(r_uint(xid)).lower().replace('l', '')
+ assert expected in xstr
+
class TestOOtype(BaseTestRclass, OORtypeMixin):
More information about the Pypy-commit
mailing list