Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: Changeset: r91068:994394c09421 Date: 2017-04-17 17:18 +0200 http://bitbucket.org/pypy/pypy/changeset/994394c09421/
Log: Move to ObjSpace the management of the thread-local set of 'currently_in_repr' objects. It will be easier to expose it to applevel, and use it in our OrderedDict. diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -311,11 +311,7 @@ def repr(self): space = self.space - ec = space.getexecutioncontext() - w_currently_in_repr = ec._py_repr - if w_currently_in_repr is None: - w_currently_in_repr = ec._py_repr = space.newdict() - return dequerepr(space, w_currently_in_repr, self) + return dequerepr(space, space.get_objects_in_repr(), self) @specialize.arg(2) def compare(self, w_other, op): @@ -428,16 +424,15 @@ app = gateway.applevel(""" def dequerepr(currently_in_repr, d): 'The app-level part of repr().' - deque_id = id(d) - if deque_id in currently_in_repr: + if d in currently_in_repr: listrepr = '[...]' else: - currently_in_repr[deque_id] = 1 + currently_in_repr[d] = 1 try: listrepr = "[" + ", ".join([repr(x) for x in d]) + ']' finally: try: - del currently_in_repr[deque_id] + del currently_in_repr[d] except: pass if d.maxlen is None: diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py --- a/pypy/objspace/std/dictmultiobject.py +++ b/pypy/objspace/std/dictmultiobject.py @@ -139,11 +139,7 @@ init_or_update(space, self, __args__, 'dict') def descr_repr(self, space): - ec = space.getexecutioncontext() - w_currently_in_repr = ec._py_repr - if w_currently_in_repr is None: - w_currently_in_repr = ec._py_repr = space.newdict() - return dictrepr(space, w_currently_in_repr, self) + return dictrepr(space, space.get_objects_in_repr(), self) def descr_eq(self, space, w_other): if space.is_w(self, w_other): @@ -468,10 +464,9 @@ def dictrepr(currently_in_repr, d): if len(d) == 0: return "{}" - dict_id = id(d) - if dict_id in currently_in_repr: + if d in currently_in_repr: return '{...}' - currently_in_repr[dict_id] = 1 + currently_in_repr[d] = 1 try: items = [] # XXX for now, we cannot use iteritems() at app-level because @@ -482,7 +477,7 @@ return "{" + ', '.join(items) + "}" finally: try: - del currently_in_repr[dict_id] + del currently_in_repr[d] except: pass ''', filename=__file__) diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -440,11 +440,7 @@ def descr_repr(self, space): if self.length() == 0: return space.newtext('[]') - ec = space.getexecutioncontext() - w_currently_in_repr = ec._py_repr - if w_currently_in_repr is None: - w_currently_in_repr = ec._py_repr = space.newdict() - return listrepr(space, w_currently_in_repr, self) + return listrepr(space, space.get_objects_in_repr(), self) def descr_eq(self, space, w_other): if not isinstance(w_other, W_ListObject): @@ -2036,15 +2032,14 @@ app = applevel(""" def listrepr(currently_in_repr, l): 'The app-level part of repr().' - list_id = id(l) - if list_id in currently_in_repr: + if l in currently_in_repr: return '[...]' - currently_in_repr[list_id] = 1 + currently_in_repr[l] = 1 try: return "[" + ", ".join([repr(x) for x in l]) + ']' finally: try: - del currently_in_repr[list_id] + del currently_in_repr[l] except: pass """, filename=__file__) diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -127,6 +127,14 @@ ec._py_repr = None return ec + def get_objects_in_repr(self): + from pypy.module.__pypy__.interp_identitydict import W_IdentityDict + ec = self.getexecutioncontext() + w_currently_in_repr = ec._py_repr + if w_currently_in_repr is None: + w_currently_in_repr = ec._py_repr = W_IdentityDict(self) + return w_currently_in_repr + def gettypefor(self, cls): return self.gettypeobject(cls.typedef) diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py --- a/pypy/objspace/std/setobject.py +++ b/pypy/objspace/std/setobject.py @@ -165,11 +165,7 @@ _initialize_set(space, self, w_iterable) def descr_repr(self, space): - ec = space.getexecutioncontext() - w_currently_in_repr = ec._py_repr - if w_currently_in_repr is None: - w_currently_in_repr = ec._py_repr = space.newdict() - return setrepr(space, w_currently_in_repr, self) + return setrepr(space, space.get_objects_in_repr(), self) def descr_cmp(self, space, w_other): if space.is_w(space.type(self), space.type(w_other)): @@ -1706,15 +1702,14 @@ app = gateway.applevel(""" def setrepr(currently_in_repr, s): 'The app-level part of repr().' - set_id = id(s) - if set_id in currently_in_repr: + if s in currently_in_repr: return '%s(...)' % (s.__class__.__name__,) - currently_in_repr[set_id] = 1 + currently_in_repr[s] = 1 try: return '%s(%s)' % (s.__class__.__name__, [x for x in s]) finally: try: - del currently_in_repr[set_id] + del currently_in_repr[s] except: pass """, filename=__file__) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit