[Python-checkins] r43641 - in python/trunk: Lib/test/test_xrange.py Objects/rangeobject.c

thomas.wouters python-checkins at python.org
Tue Apr 4 19:28:13 CEST 2006


Author: thomas.wouters
Date: Tue Apr  4 19:28:12 2006
New Revision: 43641

Modified:
   python/trunk/Lib/test/test_xrange.py
   python/trunk/Objects/rangeobject.c
Log:

Make xrange more Py_ssize_t aware, by assuming a Py_ssize_t is always at
least as big as a long. I believe this to be a safe assumption that is being
made in many parts of CPython, but a check could be added.

len(xrange(sys.maxint)) works now, so fix the testsuite's odd exception for
64-bit platforms too. It also fixes 'zip(xrange(sys.maxint), it)' as a
portable-ish (if expensive) alternative to enumerate(it); since zip() now
calls len(), this was breaking on (real) 64-bit platforms. No additional
test was added for that behaviour.



Modified: python/trunk/Lib/test/test_xrange.py
==============================================================================
--- python/trunk/Lib/test/test_xrange.py	(original)
+++ python/trunk/Lib/test/test_xrange.py	Tue Apr  4 19:28:12 2006
@@ -54,12 +54,7 @@
         self.assertRaises(OverflowError, xrange, 0, 2*sys.maxint)
 
         r = xrange(-sys.maxint, sys.maxint, 2)
-        if sys.maxint > 0x7fffffff:
-            # XXX raising ValueError is less than ideal, but this can't
-            # be fixed until range_length() returns a long in rangeobject.c
-            self.assertRaises(ValueError, len, r)
-        else:
-            self.assertEqual(len(r), sys.maxint)
+        self.assertEqual(len(r), sys.maxint)
         self.assertRaises(OverflowError, xrange, -sys.maxint-1, sys.maxint, 2)
 
 def test_main():

Modified: python/trunk/Objects/rangeobject.c
==============================================================================
--- python/trunk/Objects/rangeobject.c	(original)
+++ python/trunk/Objects/rangeobject.c	Tue Apr  4 19:28:12 2006
@@ -104,13 +104,6 @@
 static Py_ssize_t
 range_length(rangeobject *r)
 {
-#if LONG_MAX != INT_MAX /* XXX ssize_t_max */
-	if (r->len > INT_MAX) {
-		PyErr_SetString(PyExc_ValueError,
-				"xrange object size cannot be reported");
-		return -1;
-	}
-#endif
 	return (Py_ssize_t)(r->len);
 }
 


More information about the Python-checkins mailing list