[pypy-svn] r76004 - in pypy/branch/fast-forward/pypy: module/struct/test rlib/rstruct

benjamin at codespeak.net benjamin at codespeak.net
Thu Jul 8 00:52:34 CEST 2010


Author: benjamin
Date: Thu Jul  8 00:52:32 2010
New Revision: 76004

Modified:
   pypy/branch/fast-forward/pypy/module/struct/test/test_struct.py
   pypy/branch/fast-forward/pypy/rlib/rstruct/error.py
   pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
   pypy/branch/fast-forward/pypy/rlib/rstruct/standardfmttable.py
Log:
floats which are too large should actually be OverflowErrors

Modified: pypy/branch/fast-forward/pypy/module/struct/test/test_struct.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/struct/test/test_struct.py	(original)
+++ pypy/branch/fast-forward/pypy/module/struct/test/test_struct.py	Thu Jul  8 00:52:32 2010
@@ -260,7 +260,7 @@
         assert pack("<f", 12.5) == '\x00\x00HA'
         assert unpack("!f", 'AH\x00\x00') == (12.5,)
         assert unpack("<f", '\x00\x00H\xc1') == (-12.5,)
-        raises(self.struct.error, pack, "<f", 10e100)
+        raises(OverflowError, pack, "<f", 10e100)
 
     def test_bool(self):
         pack = self.struct.pack

Modified: pypy/branch/fast-forward/pypy/rlib/rstruct/error.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rstruct/error.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rstruct/error.py	Thu Jul  8 00:52:32 2010
@@ -13,3 +13,10 @@
         w_module = space.getbuiltinmodule('struct')
         w_error = space.getattr(w_module, space.wrap('error'))
         return OperationError(w_error, space.wrap(self.msg))
+
+
+class StructOverflowError(StructError):
+
+    def at_applevel(self, space):
+        from pypy.interpreter.error import OperationError
+        return OperationError(space.w_OverflowError, space.wrap(self.msg))

Modified: pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py	Thu Jul  8 00:52:32 2010
@@ -114,7 +114,7 @@
         # Raise on overflow (in some circumstances, may want to return
         # infinity instead).
         if exp >= MAX_EXP - MIN_EXP + 2:
-             raise ValueError("float too large to pack in this format")
+             raise OverflowError("float too large to pack in this format")
 
     # check constraints
     assert 0 <= mant < 1 << MANT_DIG - 1

Modified: pypy/branch/fast-forward/pypy/rlib/rstruct/standardfmttable.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rstruct/standardfmttable.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rstruct/standardfmttable.py	Thu Jul  8 00:52:32 2010
@@ -6,7 +6,7 @@
 # values when packing.
 
 import struct
-from pypy.rlib.rstruct.error import StructError
+from pypy.rlib.rstruct.error import StructError, StructOverflowError
 from pypy.rlib.rstruct import ieee
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
@@ -65,9 +65,9 @@
         fl = fmtiter.accept_float_arg()
         try:
             return ieee.pack_float(fmtiter.result, fl, size, fmtiter.bigendian)
-        except ValueError:
+        except OverflowError:
             assert size == 4
-            raise StructError("float too large to pack with format f")
+            raise StructOverflowError("float too large for format 'f'")
     return packer
 
 # ____________________________________________________________



More information about the Pypy-commit mailing list