[pypy-svn] r9266 - pypy/dist/pypy/objspace/std
ac at codespeak.net
ac at codespeak.net
Thu Feb 17 12:11:12 CET 2005
Author: ac
Date: Thu Feb 17 12:11:12 2005
New Revision: 9266
Modified:
pypy/dist/pypy/objspace/std/dictobject.py
pypy/dist/pypy/objspace/std/listobject.py
Log:
Track recursion in repr() using a per ExecutionContext dictionary.
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Thu Feb 17 12:11:12 2005
@@ -246,23 +246,27 @@
# 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_str__Dict(d):
- global _currently_in_repr
- if len(d) == 0:
- return '{}'
- if '_currently_in_repr' not in globals():
- _currently_in_repr = {}
- if id(d) in _currently_in_repr:
- return '{...}'
- try:
- _currently_in_repr[id(d)] = 1
+def app_dictstr(d):
items = []
for k, v in d.iteritems():
items.append(repr(k) + ": " + repr(v))
return "{" + ', '.join(items) + "}"
+
+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
+ try:
+ return dictstr(space, w_dict)
finally:
- del _currently_in_repr[id(d)]
+ del d[dict_id]
-repr__Dict = str__Dict = gateway.app2interp(app_str__Dict)
+repr__Dict = str__Dict
from pypy.objspace.std import dicttype
register_all(vars(), dicttype)
Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py (original)
+++ pypy/dist/pypy/objspace/std/listobject.py Thu Feb 17 12:11:12 2005
@@ -278,19 +278,22 @@
items[start+i*step] = sequence2[i]
return space.w_None
-def app_repr__List(l):
- global _currently_in_repr
- if len(l) == 0:
- return '[]'
- if '_currently_in_repr' not in globals():
- _currently_in_repr = {}
- if id(l) in _currently_in_repr:
- return '[...]'
+def app_listrepr(l):
+ 'The app-level part of repr().'
+ return "[" + ", ".join([repr(x) for x in l]) + ']'
+
+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
try:
- _currently_in_repr[id(l)] = 1
- return "[" + ", ".join([repr(x) for x in l]) + ']'
+ return listrepr(space, w_list)
finally:
- del _currently_in_repr[id(l)]
+ del d[list_id]
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