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

Random states are not marshallable across architectures #5575

Closed
vicuna opened this issue Apr 6, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Apr 6, 2012

Original bug ID: 5575
Reporter: lealanko
Assigned to: @damiendoligez
Status: closed (set by @damiendoligez on 2012-04-10T15:33:44Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.12.1
Fixed in version: 4.00.0+dev
Category: standard library
Related to: #5977
Monitored by: mehdi

Bug description

Although the Random module is designed so that it produces the same output on all architectures, the internal representation of a random state depends on the architecture: on 64-bit architectures, the state array contains some values that won't fit into an int on 32-bit architectures. Hence a Random.State.t from a 64-bit system cannot be marshalled and then unmarshalled on a 32-bit system.

This is trivial to fix: just add "land 0x3FFFFFFF" before storing a value in the state array.

Steps to reproduce

On 64-bit:

Marshal.to_string (Random.State.make [||]) [];;

  • : string =
    "\132\149\166\190\000\000\001~\000\000\000\002\000\000\000;\000\000\000;\160\b\000\000\220\000\003\000\000\000\000\196\146\178\147\003\000\000\000\000\228FXM\002Q'\236\001\002f\239\t\161\002X\195\177F\002P\127W\144\0024r\149\203\003\000\000\000\000\139\133Ro\002K\146K|\002s\196\192)\003\000\000\000\000\173\178\021\209\002\b\194\202\003\000\000\000\000\152\137\186\224\003\000\000\000\000\231e\228\246\002r,,6\002yv\150\244\003\000\000\000\000\250\224\233T\003\000\000\000\000\135}\182\205\003\000\000\000\000\209\168V.\003\000\000\000\000\146\210t\176\002lo\025\003\000\000\000\000\255H8\199\002\017\243\136\188\002HPJx\003\000\000\000\000\228\207*n\002(\184\177Q\003\000\000\000\000\185}\186U\002\015k\206 \003\000\000\000\000\233>\185\222\002-\149\197\194\003\000\000\000\000\243\215[\186\0022=%\138\002-\231\218\025\002g\244\133Z\003\000\000\000\000\169\248\132\202\002d\235+\170\002n\217\147\149\002_\185$!\002c\137\162\200\002:\135fo\002X}\180U\003\000\000\000\000\164[u\234\002G\179\234=\003\000\000\000\000\230\156r\019\003\000\000\000\000\155\252\162\255\003\000\000\000\000\245b9\021\003\000\000\000\000\246\254\198\152\002\t\158R\222\002T\210%\205\003\000\000\000\000\203\252\207\213\003\000\000\000\000\233\011P\219\003\000\000\000\000\171\206\143'\003\000\000\000\000\133\244V\151\002+"\145\165\002\020\139\169\031@"

On 32-bit:

let s : Random.State.t = Marshal.from_string "\132\149\166\190\000\000\001~\000\000\000\002\000\000\000;\000\000\000;\160\b\000\000\220\000\003\000\000\000\000\196\146\178\147\003\000\000\000\000\228FXM\002Q'\236\001\002f\239\t\161\002X\195\177F\002P\127W\144\0024r\149\203\003\000\000\000\000\139\133Ro\002K\146K|\002s\196\192)\003\000\000\000\000\173\178\021\209\002\b\194\202\003\000\000\000\000\152\137\186\224\003\000\000\000\000\231e\228\246\002r,,6\002yv\150\244\003\000\000\000\000\250\224\233T\003\000\000\000\000\135}\182\205\003\000\000\000\000\209\168V.\003\000\000\000\000\146\210t\176\002lo\025\003\000\000\000\000\255H8\199\002\017\243\136\188\002HPJx\003\000\000\000\000\228\207*n\002(\184\177Q\003\000\000\000\000\185}\186U\002\015k\206 \003\000\000\000\000\233>\185\222\002-\149\197\194\003\000\000\000\000\243\215[\186\0022=%\138\002-\231\218\025\002g\244\133Z\003\000\000\000\000\169\248\132\202\002d\235+\170\002n\217\147\149\002_\185$!\002c\137\162\200\002:\135fo\002X}\180U\003\000\000\000\000\164[u\234\002G\179\234=\003\000\000\000\000\230\156r\019\003\000\000\000\000\155\252\162\255\003\000\000\000\000\245b9\021\003\000\000\000\000\246\254\198\152\002\t\158R\222\002T\210%\205\003\000\000\000\000\203\252\207\213\003\000\000\000\000\233\011P\219\003\000\000\000\000\171\206\143'\003\000\000\000\000\133\244V\151\002+"\145\165\002\020\139\169\031@" 0;;

Exception: Failure "input_value: integer too large".
@vicuna

This comment has been minimized.

Copy link
Author

commented Apr 10, 2012

Comment author: @damiendoligez

Fixed in version 4.00 (commit 12333) and trunk (commit 12335).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.