[issue1727780] 64/32-bit issue when unpickling random.Random

Shawn Ligocki report at bugs.python.org
Mon Sep 17 12:13:41 CEST 2007


Shawn Ligocki added the comment:

I've got a patch! The problem was that the state was being cast from a
C-type unsigned long to a long.

On 32-bit machines this makes large 32-bit longs negative.
On 64-bit machines this preserves the sign of 32-bit values (because
they are stored in 64-bit longs).

My patch returns the values with PyLong_FromUnsignedLong() instead of
PyInt_FromLong(), therefore there is no casting to long and both 32-bit
and 64-bit machines produce the same result.

I added code to read states from the old (buggy) version and decypher it
appropriately (from either 32-bit or 64-bit source!). In other words,
old pickles can now be opened on either architecture with the new patch.

This patch is taken from the svn head, but also works on Python 2.5.1 .

I haven't tested this patch fully on 64-bit machine yet. I'll let you
know when I have.

Cheers,
-Shawn

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1727780>
_____________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python_head_random.patch
Type: text/x-diff
Size: 2944 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-bugs-list/attachments/20070917/784ec72c/attachment.patch 


More information about the Python-bugs-list mailing list