From 4cef81660297cbdf3da8e130b1dadc88e370f77c Mon Sep 17 00:00:00 2001 From: Anthony Baxter Date: Thu, 6 Nov 2003 13:40:46 +0000 Subject: [PATCH] On RH10, the PIE additions to gcc mean that id() can sometimes be a very large 32 bit int, which comes out as a negative int. Workaround this to prevent warnings from the test suite. --- Lib/repr.py | 8 ++++++-- Lib/test/test_repr.py | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/repr.py b/Lib/repr.py index 0431857bbe67..dedf6aa3af12 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -2,6 +2,8 @@ __all__ = ["Repr","repr"] +import sys + class Repr: def __init__(self): self.maxlevel = 6 @@ -101,8 +103,10 @@ class Repr: # Bugs in x.__repr__() can cause arbitrary # exceptions -- then make up something except: - return '<' + x.__class__.__name__ + ' instance at ' + \ - hex(id(x))[2:] + '>' + # On some systems (RH10) id() can be a negative number. + # work around this. + MAX = 2L*sys.maxint+1 + return '<' + x.__class__.__name__ + ' instance at %x>'%(id(x)&MAX) if len(s) > self.maxstring: i = max(0, (self.maxstring-3)//2) j = max(0, self.maxstring-3-i) diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index 29e1687a2d03..0a032ea258f1 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -88,7 +88,10 @@ class ReprTests(unittest.TestCase): eq(r(i2), expected) i3 = ClassWithFailingRepr() - eq(r(i3), (""%id(i3))) + # On some systems (RH10) id() can be a negative number. + # work around this. + MAX = 2L*sys.maxint+1 + eq(r(i3), (""%(id(i3)&MAX))) s = r(ClassWithFailingRepr) self.failUnless(s.startswith("