Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

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

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Sep 15, 2007, 10:08 PM

Post #1 of 7 (334 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random

Changes by sligocki:


----------
versions: +Python 2.5 -Python 2.4

_____________________________________
Tracker <report [at] bugs>
<http://bugs.python.org/issue1727780>
_____________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Sep 15, 2007, 10:14 PM

Post #2 of 7 (310 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random [In reply to]

sligocki added the comment:

I've had this same problem with 2.5.1

Pickling random.getstate() on 64bit and then loading it back with
random.setstate() on 32bit does not work (crashes because of trying cast
64bit ints to 32bit).

The other way around is even worse. It loads but is in a faulty state,
where for example:
>>> random.randrange(1000)
49801980494

This seems like a bug to me.

----------
nosy: +sligocki

_____________________________________
Tracker <report [at] bugs>
<http://bugs.python.org/issue1727780>
_____________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Sep 16, 2007, 9:05 AM

Post #3 of 7 (304 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random [In reply to]

Martin v. Löwis added the comment:

Would anybody of you like to work on a patch?

----------
nosy: +loewis

_____________________________________
Tracker <report [at] bugs>
<http://bugs.python.org/issue1727780>
_____________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Sep 17, 2007, 3:13 AM

Post #4 of 7 (299 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random [In reply to]

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>
<http://bugs.python.org/issue1727780>
_____________________________________
Attachments: python_head_random.patch (2.88 KB)


report at bugs

Sep 17, 2007, 2:47 PM

Post #5 of 7 (304 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random [In reply to]

Changes by Martin v. Löwis:


----------
keywords: +patch

_____________________________________
Tracker <report [at] bugs>
<http://bugs.python.org/issue1727780>
_____________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Sep 17, 2007, 10:41 PM

Post #6 of 7 (299 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random [In reply to]

Shawn Ligocki added the comment:

Yep, tested it on a 64-bit machine and 2 32-bit machines and back and
forth between them. It seems to resolve the problem.

_____________________________________
Tracker <report [at] bugs>
<http://bugs.python.org/issue1727780>
_____________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Sep 23, 2007, 1:32 AM

Post #7 of 7 (291 views)
Permalink
[issue1727780] 64/32-bit issue when unpickling random.Random [In reply to]

Changes by Martin v. Löwis:


----------
assignee: -> loewis
severity: normal -> major

_____________________________________
Tracker <report [at] bugs>
<http://bugs.python.org/issue1727780>
_____________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.