]> granicus.if.org Git - python/commitdiff
Merged revisions 68903,68906 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Sat, 24 Jan 2009 21:46:33 +0000 (21:46 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 24 Jan 2009 21:46:33 +0000 (21:46 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68903 | mark.dickinson | 2009-01-24 16:40:29 +0000 (Sat, 24 Jan 2009) | 5 lines

  Issue #1672332: Fix unpickling of subnormal floats, which was raising
  ValueError on some platforms as a result of the platform strtod setting
  errno on underflow.
........
  r68906 | mark.dickinson | 2009-01-24 21:08:38 +0000 (Sat, 24 Jan 2009) | 2 lines

  Issue #3657: fix occasional test_pickletools failures.
........

Lib/pickletools.py
Lib/test/pickletester.py
Misc/NEWS
Modules/_pickle.c

index 6614df718a2199f5bbec9de883adcc3ceb867c1f..cfd5fccb98b53ec35281182071d2effe79f6e487 100644 (file)
@@ -2128,11 +2128,11 @@ highest protocol among opcodes = 1
 
 Exercise the INST/OBJ/BUILD family.
 
->>> import random
->>> dis(pickle.dumps(random.getrandbits, 0))
-    0: c    GLOBAL     'random getrandbits'
-   20: p    PUT        0
-   23: .    STOP
+>>> import pickletools
+>>> dis(pickle.dumps(pickletools.dis, 0))
+    0: c    GLOBAL     'pickletools dis'
+   17: p    PUT        0
+   20: .    STOP
 highest protocol among opcodes = 0
 
 >>> from pickletools import _Example
index 3ed84fb07e8a00aa6d7d43992cb7774d8fcb67a6..51dd0fc439ad7bb7a25037b26d9c2549fa89b7fb 100644 (file)
@@ -545,6 +545,16 @@ class AbstractPickleTests(unittest.TestCase):
             got = self.loads(p)
             self.assertEqual(n, got)
 
+    def test_float(self):
+        test_values = [0.0, 4.94e-324, 1e-310, 7e-308, 6.626e-34, 0.1, 0.5,
+                       3.14, 263.44582062374053, 6.022e23, 1e30]
+        test_values = test_values + [-x for x in test_values]
+        for proto in protocols:
+            for value in test_values:
+                pickle = self.dumps(value, proto)
+                got = self.loads(pickle)
+                self.assertEqual(value, got)
+
     @run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
     def test_float_format(self):
         # make sure that floats are formatted locale independent with proto 0
index 53cd724f9d270500efc5bc5c9a8e0a6e63672279..5f8eda5f75f2c9398aecf3058b6e0c6683af6bc0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -139,6 +139,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #1672332: fix unpickling of subnormal floats, which was
+  producing a ValueError on some platforms.
+
 - Issue #3881: Help Tcl to load even when started through the
   unreadable local symlink to "Program Files" on Vista.
 
index 6536e6f16041c56cc912ef4264f38d6a65cc69d2..5813fd49492dbd42ddd47e7ea2436c8a1171e1e2 100644 (file)
@@ -2958,7 +2958,8 @@ load_float(UnpicklerObject *self)
     errno = 0;
     d = PyOS_ascii_strtod(s, &endptr);
 
-    if (errno || (endptr[0] != '\n') || (endptr[1] != '\0')) {
+    if ((errno == ERANGE && !(fabs(d) <= 1.0)) ||
+        (endptr[0] != '\n') || (endptr[1] != '\0')) {
         PyErr_SetString(PyExc_ValueError, "could not convert string to float");
         return -1;
     }