From: Mark Dickinson Date: Sat, 24 Jan 2009 21:47:45 +0000 (+0000) Subject: Merged revisions 68908 via svnmerge from X-Git-Tag: v3.0.1~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3128db9f22e6c0d1993211899e8fdd9a86b6bcf;p=thirdparty%2FPython%2Fcpython.git Merged revisions 68908 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r68908 | mark.dickinson | 2009-01-24 21:46:33 +0000 (Sat, 24 Jan 2009) | 15 lines Merged revisions 68903,68906 via svnmerge from 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. ........ ................ --- diff --git a/Lib/pickletools.py b/Lib/pickletools.py index 6614df718a21..cfd5fccb98b5 100644 --- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -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 diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 4cebcd7bbc9f..770e631e8bec 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index 673079a1e2ed..e79f1f8dda07 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -100,6 +100,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. diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 02a3e447d907..63ace099751a 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -2969,7 +2969,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; }