diff options
Diffstat (limited to 'Modules/_randommodule.c')
-rw-r--r-- | Modules/_randommodule.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 3256bf1..c791909 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -319,7 +319,7 @@ random_getstate(RandomObject *self) if (state == NULL) return NULL; for (i=0; i<N ; i++) { - element = PyLong_FromLong((long)(self->state[i])); + element = PyLong_FromUnsignedLong(self->state[i]); 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 = PyLong_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 = PyLong_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; |