[pypy-svn] r9376 - pypy/dist/pypy/objspace/std

ac at codespeak.net ac at codespeak.net
Mon Feb 21 11:25:13 CET 2005


Author: ac
Date: Mon Feb 21 11:25:13 2005
New Revision: 9376

Modified:
   pypy/dist/pypy/objspace/std/dictobject.py
   pypy/dist/pypy/objspace/std/listobject.py
Log:
Use applevel dict to keep track of objects.

Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictobject.py	Mon Feb 21 11:25:13 2005
@@ -246,26 +246,34 @@
 # The fix is to move this to dicttype.py, and do a
 # multimethod lookup mapping str to StdObjSpace.str
 # This cannot happen until multimethods are fixed. See dicttype.py
-def app_dictstr(d):
+def app_dictstr(currently_in_repr, d):
+    dict_id = id(d)
+    if dict_id in currently_in_repr:
+        return '{...}'
+    currently_in_repr[dict_id] = 1
+    try:
         items = []
         for k, v in d.iteritems():
             items.append(repr(k) + ": " + repr(v))
         return "{" +  ', '.join(items) + "}"
+    finally:
+        try:
+            del currently_in_repr[dict_id]
+        except:
+            pass
 
 dictstr = gateway.app2interp(app_dictstr)
 
 def str__Dict(space, w_dict):
     if w_dict.used == 0:
         return space.wrap('{}')
-    d = space.get_ec_state_dict().setdefault('Py_Repr', {})
-    dict_id = space.int_w(space.id(w_dict))
-    if dict_id in d:
-        return space.wrap('{...}')
-    d[dict_id] = 1
+    statedict = space.get_ec_state_dict()
     try:
-        return dictstr(space, w_dict)
-    finally:
-        del d[dict_id]
+        w_currently_in_repr = statedict['Py_Repr']
+    except KeyError:
+        w_currently_in_repr = statedict['Py_Repr'] = space.newdict(())
+
+    return dictstr(space, w_currently_in_repr, w_dict)
 
 repr__Dict = str__Dict
 from pypy.objspace.std import dicttype

Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/listobject.py	Mon Feb 21 11:25:13 2005
@@ -278,22 +278,30 @@
         items[start+i*step] = sequence2[i]
     return space.w_None
 
-def app_listrepr(l):
+def app_listrepr(currently_in_repr, l):
     'The app-level part of repr().'
-    return "[" + ", ".join([repr(x) for x in l]) + ']'
-
+    list_id = id(l)
+    if list_id in currently_in_repr:
+        return '[...]'
+    currently_in_repr[list_id] = 1
+    try:
+        return "[" + ", ".join([repr(x) for x in l]) + ']'
+    finally:
+        try:
+            del currently_in_repr[list_id]
+        except:
+            pass
+        
 def repr__List(space, w_list):
     if w_list.ob_size == 0:
         return space.wrap('[]')
-    d = space.get_ec_state_dict().setdefault('Py_Repr', {})
-    list_id = space.int_w(space.id(w_list))
-    if list_id in d:
-        return space.wrap('[...]')
-    d[list_id] = 1
+    statedict = space.get_ec_state_dict()
     try:
-        return listrepr(space, w_list)
-    finally:
-        del d[list_id]
+        w_currently_in_repr = statedict['Py_Repr']
+    except KeyError:
+        w_currently_in_repr = statedict['Py_Repr'] = space.newdict(())
+
+    return listrepr(space, w_currently_in_repr, w_list)
 
 def hash__List(space,w_list):
     raise OperationError(space.w_TypeError,space.wrap("list objects are unhashable"))



More information about the Pypy-commit mailing list