[ZODB-Dev] Problem Storing Infinity
Tim Peters
tim.peters at gmail.com
Tue Sep 12 15:07:46 EDT 2006
[David Binger]
>>> That's interesting.
>>> It appears that pickle protocol 2 chokes on inf.
[Tim Peters]
>> As above. BTW, why protocol 2 specifically? Protocols 1 and 2 treat
>> floats the same way.
[David]
> I was thinking that the default protocol is 1, but I see
> now that the default is 0.
Strange, eh? Since only protocol 0 existed at first, I suppose this
was a nod to backward compatibility.
> 2.4.2 on OS X can pickle infinity using
> protocol 0, but attempts to pickle infinity using protocols
> 1 or 2 raise a SystemError.
All of which are platform-dependent accidents.
> Pickling infinity works fine, just as you say, in 2.5,
> using any of the protocols.
Well, I meant what I said ;-):
In 2.5, marshal and pickle (but only with protocol >= 1) can at
least pack and unpack them reliably across most IEEE-754 boxes.
It's /still/ an accident that protocol 0 worked for you under 2.5.
WinTel is the major example of a 754 box where protocol 0 still
doesn't work under 2.5, and probably never will (Microsoft's C
implementation can't read the strings it produces for infinities or
NaNs, which pretty much dooms "text mode" pickles forever in those
cases):
Python 2.6a0 (trunk:51860, Sep 11 2006, 15:23:15) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cPickle
>>> p = cPickle.dumps(1e300 * 1e300)
>>> p
'F1.#INF\n.'
>>> cPickle.loads(p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float
>>> p = cPickle.dumps(1e300 * 1e300, 1)
>>> cPickle.loads(p)
1.#INF
So protocol 0 still fails, while protocol 1 (or higher) works, and all
of them fail on WinTel before 2.5.
> Thanks for the explanation.
Hey, it's always my pleasure to spread fear :-)
More information about the ZODB-Dev
mailing list