Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32/64bit pickled Random incompatiblity #43245

Closed
pm67nz mannequin opened this issue Apr 19, 2006 · 5 comments
Closed

32/64bit pickled Random incompatiblity #43245

pm67nz mannequin opened this issue Apr 19, 2006 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@pm67nz
Copy link
Mannequin

pm67nz mannequin commented Apr 19, 2006

BPO 1472695
Nosy @tim-one, @rhettinger
Files
  • bug1472695.patch: A patch to _randommodule.c
  • bug1472695.patch: A slightly better patch to _randommodule.c
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2006-04-26.00:26:43.000>
    created_at = <Date 2006-04-19.01:10:57.000>
    labels = ['library']
    title = '32/64bit pickled Random incompatiblity'
    updated_at = <Date 2006-04-26.00:26:43.000>
    user = 'https://bugs.python.org/pm67nz'

    bugs.python.org fields:

    activity = <Date 2006-04-26.00:26:43.000>
    actor = 'tim.peters'
    assignee = 'rhettinger'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-04-19.01:10:57.000>
    creator = 'pm67nz'
    dependencies = []
    files = ['1976', '1977']
    hgrepos = []
    issue_num = 1472695
    keywords = []
    message_count = 5.0
    messages = ['28294', '28295', '28296', '28297', '28298']
    nosy_count = 4.0
    nosy_names = ['tim.peters', 'nnorwitz', 'rhettinger', 'pm67nz']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1472695'
    versions = ['Python 2.4']

    @pm67nz
    Copy link
    Mannequin Author

    pm67nz mannequin commented Apr 19, 2006

    The unsigned long integers which make up the state of a Random
    instance are converted to Python integers via a cast to long in
    _randommodule.c's random_getstate function, so on a 32bit platform
    Random.getstate() returns a mix of postitive and negative integers, while
    on a 64bit platform the negative numbers are replaced by larger positive
    numbers, their 32bit-2s-complement equivalents.

    As a result, unpicking a Random instance from a 64bit machine on a 32bit
    platform produces the error "OverflowError: long int too large to convert
    to int". Unpickling a 32bit Random on a 64bit machine succeeds, but the
    resulting object is in a slightly confused state:

    >>> r32 = cPickle.load(open('r32_3.pickle'))
    >>> for i in range(3):
    ...     print r64.random(), r32.random()
    ... 
    0.237964627092 4292886520.32
    0.544229225296 0.544229225296
    0.369955166548 4292886520.19

    @pm67nz pm67nz mannequin closed this as completed Apr 19, 2006
    @pm67nz pm67nz mannequin assigned rhettinger Apr 19, 2006
    @pm67nz pm67nz mannequin added the stdlib Python modules in the Lib dir label Apr 19, 2006
    @pm67nz pm67nz mannequin closed this as completed Apr 19, 2006
    @pm67nz pm67nz mannequin assigned rhettinger Apr 19, 2006
    @pm67nz pm67nz mannequin added the stdlib Python modules in the Lib dir label Apr 19, 2006
    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Apr 19, 2006

    Logged In: YES
    user_id=33168

    Peter, thanks for the report. Do you think you could work
    up a patch to correct this problem?

    @pm67nz
    Copy link
    Mannequin Author

    pm67nz mannequin commented Apr 21, 2006

    Logged In: YES
    user_id=320286

    OK, here is a candidate patch, though I don't know if it is the best way to do it
    or meets the style guidelines etc. It makes Random pickles interchangable
    between 32bit and 64bit machines by encoding their states as Python long
    integers. An old pre-patch 32bit pickle loaded on a 64bit machine still fails
    (OverflowError: can't convert negative value to unsigned long) but I hope that
    combination is rare enough to ignore. Also on a 32bit machine new Random
    pickles can't be unpickled by a pre-patch python, but again there are limits to
    sane backward compatability.

    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    Tim, do you think we should require that the world not
    change for 32-bit pickles?

    @tim-one
    Copy link
    Member

    tim-one commented Apr 26, 2006

    Logged In: YES
    user_id=31435

    do you think we should require that the world not
    change for 32-bit pickles?

    I don't understand the question. If a pre-2.5 pickle here
    can be read in 2.5, where both producer & consumer are the
    same 32-vs-64 bit choice; and a 2.5+ pickle here is portable
    between 32- and 64- boxes, I'd say "good enough".

    While desirable, it's not really critical that a 2.5 pickle
    here be readable by an older Python. While that's critical
    for pickle in general, and critical too for
    everyone-uses-'em types (ints, strings, lists, ...), when
    fixing a bug in a specific rarely-used type's pickling
    strategy some slop is OK. IOW, it's just not worth heroic
    efforts to hide all pain. The docs should mention
    incompatibilities, though.

    Does that answer the question?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants