From 6b449f4f2bd86c104a8b57547428eb9bb3a182b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 3 Dec 2007 19:20:02 +0000 Subject: 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. --- Modules/_randommodule.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'Modules/_randommodule.c') 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; istate[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; istate[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; -- cgit v1.2.1