diff options
| author | Martin v. Löwis <martin@v.loewis.de> | 2007-12-03 19:20:02 +0000 |
|---|---|---|
| committer | Martin v. Löwis <martin@v.loewis.de> | 2007-12-03 19:20:02 +0000 |
| commit | 6b449f4f2bd86c104a8b57547428eb9bb3a182b0 (patch) | |
| tree | 6ca8ed3d8b4ab7fa6175675e78fba0c481d30d10 /Modules/_randommodule.c | |
| parent | 2ec7415db5ad63c4e4b27ee793214071454f6fe5 (diff) | |
| download | cpython-git-6b449f4f2bd86c104a8b57547428eb9bb3a182b0.tar.gz | |
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
Diffstat (limited to 'Modules/_randommodule.c')
| -rw-r--r-- | Modules/_randommodule.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 25adc2e120..e439f1e945 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -319,12 +319,12 @@ random_getstate(RandomObject *self) if (state == NULL) return NULL; for (i=0; i<N ; i++) { - element = PyInt_FromLong((long)(self->state[i])); + element = PyLong_FromUnsignedLong(self->state[i]); if (element == NULL) goto Fail; PyTuple_SET_ITEM(state, i, element); } - element = PyInt_FromLong((long)(self->index)); + element = PyLong_FromLong((long)(self->index)); if (element == NULL) goto Fail; PyTuple_SET_ITEM(state, i, element); @@ -339,7 +339,8 @@ static PyObject * random_setstate(RandomObject *self, PyObject *state) { int i; - long element; + unsigned long element; + long index; if (!PyTuple_Check(state)) { PyErr_SetString(PyExc_TypeError, @@ -353,16 +354,16 @@ random_setstate(RandomObject *self, PyObject *state) } for (i=0; i<N ; i++) { - element = PyInt_AsLong(PyTuple_GET_ITEM(state, i)); + element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i)); if (element == -1 && PyErr_Occurred()) return NULL; - self->state[i] = (unsigned long)element; + self->state[i] = element & 0xffffffffUL; /* Make sure we get sane state */ } - element = PyInt_AsLong(PyTuple_GET_ITEM(state, i)); - if (element == -1 && PyErr_Occurred()) + index = PyLong_AsLong(PyTuple_GET_ITEM(state, i)); + if (index == -1 && PyErr_Occurred()) return NULL; - self->index = (int)element; + self->index = (int)index; Py_INCREF(Py_None); return Py_None; |
