[pypy-svn] r11477 - pypy/dist/pypy/annotation
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 26 15:06:00 CEST 2005
Author: arigo
Date: Tue Apr 26 15:06:00 2005
New Revision: 11477
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/model.py
Log:
Protect SomeObject.__repr__ against infinite recursion (for lists containing
themselves).
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Tue Apr 26 15:06:00 2005
@@ -9,7 +9,6 @@
from pypy.annotation.classdef import ClassDef
from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
from pypy.annotation.dictdef import DictDef, MOST_GENERAL_DICTDEF
-from pypy.tool.tls import tlsobject
from pypy.tool.hack import func_with_new_name
from pypy.interpreter.pycode import CO_VARARGS
from pypy.interpreter.pycode import cpython_code_signature
@@ -31,9 +30,6 @@
self.attrs.update(other.attrs)
-TLS = tlsobject()
-
-
class Bookkeeper:
"""The log of choices that have been made while analysing the operations.
It ensures that the same 'choice objects' will be returned if we ask
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Tue Apr 26 15:06:00 2005
@@ -32,10 +32,12 @@
import pypy
from pypy.annotation.pairtype import pair, extendabletype
from pypy.objspace.flow.model import Constant
+from pypy.tool.tls import tlsobject
import inspect
DEBUG = True # set to False to disable recording of debugging information
+TLS = tlsobject()
class SomeObject:
@@ -49,15 +51,26 @@
def __ne__(self, other):
return not (self == other)
def __repr__(self):
- items = self.__dict__.items()
- items.sort()
- args = []
- for k, v in items:
- m = getattr(self, 'fmt_' + k, repr)
- r = m(v)
- if r is not None:
- args.append('%s=%s'%(k, r))
- kwds = ', '.join(args)
+ try:
+ reprdict = TLS.reprdict
+ except AttributeError:
+ reprdict = TLS.reprdict = {}
+ if self in reprdict:
+ kwds = '...'
+ else:
+ reprdict[self] = True
+ try:
+ items = self.__dict__.items()
+ items.sort()
+ args = []
+ for k, v in items:
+ m = getattr(self, 'fmt_' + k, repr)
+ r = m(v)
+ if r is not None:
+ args.append('%s=%s'%(k, r))
+ kwds = ', '.join(args)
+ finally:
+ del reprdict[self]
return '%s(%s)' % (self.__class__.__name__, kwds)
def fmt_knowntype(self, t):
More information about the Pypy-commit
mailing list