]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
On RH10, the PIE additions to gcc mean that id() can sometimes be a very
authorAnthony Baxter <anthonybaxter@gmail.com>
Thu, 6 Nov 2003 13:40:46 +0000 (13:40 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Thu, 6 Nov 2003 13:40:46 +0000 (13:40 +0000)
large 32 bit int, which comes out as a negative int. Workaround this to
prevent warnings from the test suite.

Lib/repr.py
Lib/test/test_repr.py

index 0431857bbe675a9a5fae487d129f7ea184ced01c..dedf6aa3af12cb9a6347dac56cbfc8407ff08f7e 100644 (file)
@@ -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)
index 29e1687a2d0329f31b9970dfd822f483b649e796..0a032ea258f14cc178f586fcf8918c4e0746338e 100644 (file)
@@ -88,7 +88,10 @@ class ReprTests(unittest.TestCase):
         eq(r(i2), expected)
 
         i3 = ClassWithFailingRepr()
-        eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3)))
+        # On some systems (RH10) id() can be a negative number. 
+        # work around this.
+        MAX = 2L*sys.maxint+1
+        eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%(id(i3)&MAX)))
 
         s = r(ClassWithFailingRepr)
         self.failUnless(s.startswith("<class "))