From: <zy...@us...> - 2008-08-03 04:45:41
|
Revision: 5061 http://jython.svn.sourceforge.net/jython/?rev=5061&view=rev Author: zyasoft Date: 2008-08-03 04:45:39 +0000 (Sun, 03 Aug 2008) Log Message: ----------- Allow typecodes of B, H, I to fully use their storage. Don't run test_byteswap for u (Unicode) because it doesn't make sense given UTF-16 decoding. Fixes test_array. Modified Paths: -------------- branches/asm/Lib/test/test_array.py branches/asm/src/org/python/core/PyArray.java Modified: branches/asm/Lib/test/test_array.py =================================================================== --- branches/asm/Lib/test/test_array.py 2008-08-03 04:45:30 UTC (rev 5060) +++ branches/asm/Lib/test/test_array.py 2008-08-03 04:45:39 UTC (rev 5061) @@ -74,6 +74,10 @@ self.assertEqual(bi[1], len(a)) def test_byteswap(self): + if test_support.is_jython and self.typecode == 'u': + # Jython unicodes are already decoded from utf16, + # so this doesn't make sense + return a = array.array(self.typecode, self.example) self.assertRaises(TypeError, a.byteswap, 42) if a.itemsize in (1, 2, 4, 8): @@ -912,11 +916,12 @@ lower = 0 itemsize = a.itemsize if test_support.is_jython: - # XXX: unsigned itemsizes are larger than would be expected - # in CPython - itemsize /= 2 - #upper = long(pow(2, a.itemsize * 8)) - 1L - upper = long(pow(2, itemsize * 8)) - 1L + # unsigned itemsizes are larger than would be expected + # in CPython because Jython promotes to the next size + # (Java has no unsiged integers except for char) + upper = long(pow(2, a.itemsize * 8 - 1)) - 1L + else: + upper = long(pow(2, a.itemsize * 8)) - 1L self.check_overflow(lower, upper) Modified: branches/asm/src/org/python/core/PyArray.java =================================================================== --- branches/asm/src/org/python/core/PyArray.java 2008-08-03 04:45:30 UTC (rev 5060) +++ branches/asm/src/org/python/core/PyArray.java 2008-08-03 04:45:39 UTC (rev 5061) @@ -1327,7 +1327,6 @@ return; } - // check for overflow of the integral types if(type == Byte.TYPE) { long val; try { @@ -1337,7 +1336,7 @@ } if(val < (isSigned() ? 0 : Byte.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > (isSigned() ? Byte.MAX_VALUE * 2 + 1 : Byte.MAX_VALUE)) { + } else if(val > Byte.MAX_VALUE) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Short.TYPE) { @@ -1349,7 +1348,7 @@ } if(val < (isSigned() ? 0 : Short.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > (isSigned() ? Byte.MAX_VALUE * 2 + 1 : Short.MAX_VALUE)) { + } else if(val > Short.MAX_VALUE) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Integer.TYPE) { @@ -1361,7 +1360,7 @@ } if(val < (isSigned() ? 0 : Integer.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > (isSigned() ? Short.MAX_VALUE * 2 + 1 : Integer.MAX_VALUE)) { + } else if(val > Integer.MAX_VALUE) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Long.TYPE) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |