Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cddcf44

Browse files
committed
Merged revisions 68903,68906 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 3dfe55b commit cddcf44

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

Lib/pickletools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,11 +2128,11 @@ def __init__(self, value):
21282128
21292129
Exercise the INST/OBJ/BUILD family.
21302130
2131-
>>> import random
2132-
>>> dis(pickle.dumps(random.getrandbits, 0))
2133-
0: c GLOBAL 'random getrandbits'
2134-
20: p PUT 0
2135-
23: . STOP
2131+
>>> import pickletools
2132+
>>> dis(pickle.dumps(pickletools.dis, 0))
2133+
0: c GLOBAL 'pickletools dis'
2134+
17: p PUT 0
2135+
20: . STOP
21362136
highest protocol among opcodes = 0
21372137
21382138
>>> from pickletools import _Example

Lib/test/pickletester.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,16 @@ def test_long(self):
545545
got = self.loads(p)
546546
self.assertEqual(n, got)
547547

548+
def test_float(self):
549+
test_values = [0.0, 4.94e-324, 1e-310, 7e-308, 6.626e-34, 0.1, 0.5,
550+
3.14, 263.44582062374053, 6.022e23, 1e30]
551+
test_values = test_values + [-x for x in test_values]
552+
for proto in protocols:
553+
for value in test_values:
554+
pickle = self.dumps(value, proto)
555+
got = self.loads(pickle)
556+
self.assertEqual(value, got)
557+
548558
@run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
549559
def test_float_format(self):
550560
# make sure that floats are formatted locale independent with proto 0

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Core and Builtins
139139
Library
140140
-------
141141

142+
- Issue #1672332: fix unpickling of subnormal floats, which was
143+
producing a ValueError on some platforms.
144+
142145
- Issue #3881: Help Tcl to load even when started through the
143146
unreadable local symlink to "Program Files" on Vista.
144147

Modules/_pickle.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,8 @@ load_float(UnpicklerObject *self)
29582958
errno = 0;
29592959
d = PyOS_ascii_strtod(s, &endptr);
29602960

2961-
if (errno || (endptr[0] != '\n') || (endptr[1] != '\0')) {
2961+
if ((errno == ERANGE && !(fabs(d) <= 1.0)) ||
2962+
(endptr[0] != '\n') || (endptr[1] != '\0')) {
29622963
PyErr_SetString(PyExc_ValueError, "could not convert string to float");
29632964
return -1;
29642965
}

0 commit comments

Comments
 (0)