[Python-checkins] python/nondist/sandbox/twister _random.c,1.20,1.21
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sun, 29 Dec 2002 01:12:28 -0800
Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv11200
Modified Files:
_random.c
Log Message:
random_seed(): More localization, catch more errors, *always* jump to
Done in error cases (it's the only robust way to make sure no decrefs
are missing as time goes on and the code gets fiddled).
Index: _random.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/_random.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** _random.c 29 Dec 2002 09:05:46 -0000 1.20
--- _random.c 29 Dec 2002 09:12:26 -0000 1.21
***************
*** 212,221 ****
unsigned long seed;
unsigned int i;
! PyObject *split;
PyObject *arg = NULL;
! PyObject *masklower;
! PyObject *thirtytwo;
! int err;
! long hash;
if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg))
--- 212,219 ----
unsigned long seed;
unsigned int i;
! PyObject *split = NULL;
PyObject *arg = NULL;
! PyObject *masklower = NULL;
! PyObject *thirtytwo = NULL;
if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg))
***************
*** 233,256 ****
split = PyList_New(0);
if (split == NULL)
! return NULL;
if (PyInt_Check(arg) || PyLong_Check(arg))
arg = PyNumber_Absolute(arg);
else {
! hash = PyObject_Hash(arg);
! if (hash != -1)
! arg = PyLong_FromUnsignedLong((unsigned long)hash);
! else
! arg = NULL;
! }
! if (arg == NULL) {
! Py_DECREF(split);
! return NULL;
}
masklower = PyLong_FromUnsignedLong(0xffffffffU);
thirtytwo = PyInt_FromLong(32L);
while (PyObject_IsTrue(arg)) {
PyObject *little;
PyObject *newarg;
little = PyNumber_And(arg, masklower);
--- 231,256 ----
split = PyList_New(0);
if (split == NULL)
! goto Done;
if (PyInt_Check(arg) || PyLong_Check(arg))
arg = PyNumber_Absolute(arg);
else {
! long hash = PyObject_Hash(arg);
! if (hash == -1)
! goto Done;
! arg = PyLong_FromUnsignedLong((unsigned long)hash);
}
+ if (arg == NULL)
+ goto Done;
masklower = PyLong_FromUnsignedLong(0xffffffffU);
+ if (masklower == NULL)
+ goto Done;
thirtytwo = PyInt_FromLong(32L);
+ if (thirtytwo == NULL)
+ goto Done;
while (PyObject_IsTrue(arg)) {
PyObject *little;
PyObject *newarg;
+ int err;
little = PyNumber_And(arg, masklower);
***************
*** 289,294 ****
Py_XDECREF(masklower);
Py_XDECREF(thirtytwo);
! Py_DECREF(arg);
! Py_DECREF(split);
return result;
}
--- 289,294 ----
Py_XDECREF(masklower);
Py_XDECREF(thirtytwo);
! Py_XDECREF(arg);
! Py_XDECREF(split);
return result;
}