[Python-checkins] python/nondist/sandbox/twister _random.c,1.21,1.22

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月29日 01:18:02 -0800


Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv12057
Modified Files:
	_random.c 
Log Message:
random_seed(): Don't try reusing the name "arg" as a general vrbl name.
The result of that is always that some error path manages to leave arg
at its original value when you get to the end, and then there's a deadly
decref of the borrowed reference.
Index: _random.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/_random.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** _random.c	29 Dec 2002 09:12:26 -0000	1.21
--- _random.c	29 Dec 2002 09:18:00 -0000	1.22
***************
*** 213,219 ****
 	unsigned int i;
 	PyObject *split = NULL;
- 	PyObject *arg = NULL;
 	PyObject *masklower = NULL;
 	PyObject *thirtytwo = NULL;
 
 	if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg))
--- 213,221 ----
 	unsigned int i;
 	PyObject *split = NULL;
 	PyObject *masklower = NULL;
 	PyObject *thirtytwo = NULL;
+ 	PyObject *n = NULL;
+ 
+ 	PyObject *arg = NULL;
 
 	if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg))
***************
*** 234,245 ****
 
 	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);
--- 236,247 ----
 
 	if (PyInt_Check(arg) || PyLong_Check(arg))
! 		n = PyNumber_Absolute(arg);
 	else {
 		long hash = PyObject_Hash(arg);
 		if (hash == -1)
 			goto Done;
! 		n = PyLong_FromUnsignedLong((unsigned long)hash);
 	}
! 	if (n == NULL)
 		goto Done;
 	masklower = PyLong_FromUnsignedLong(0xffffffffU);
***************
*** 249,258 ****
 	if (thirtytwo == NULL)
 		goto Done;
! 	while (PyObject_IsTrue(arg)) {
 		PyObject *little;
! 		PyObject *newarg;
 		int err;
 
! 		little = PyNumber_And(arg, masklower);
 		if (little == NULL)
 			goto Done;
--- 251,260 ----
 	if (thirtytwo == NULL)
 		goto Done;
! 	while (PyObject_IsTrue(n)) {
 		PyObject *little;
! 		PyObject *newn;
 		int err;
 
! 		little = PyNumber_And(n, masklower);
 		if (little == NULL)
 			goto Done;
***************
*** 262,270 ****
 		if (err == -1)
 			goto Done;
! 		newarg = PyNumber_Rshift(arg, thirtytwo);
! 		if (newarg == NULL)
 			goto Done;
! 		Py_DECREF(arg);
! 		arg = newarg;
 	}
 
--- 264,272 ----
 		if (err == -1)
 			goto Done;
! 		newn = PyNumber_Rshift(n, thirtytwo);
! 		if (newn == NULL)
 			goto Done;
! 		Py_DECREF(n);
! 		n = newn;
 	}
 
***************
*** 289,293 ****
 	Py_XDECREF(masklower);
 	Py_XDECREF(thirtytwo);
! 	Py_XDECREF(arg);
 	Py_XDECREF(split);
 	return result;
--- 291,295 ----
 	Py_XDECREF(masklower);
 	Py_XDECREF(thirtytwo);
! 	Py_XDECREF(n);
 	Py_XDECREF(split);
 	return result;

AltStyle によって変換されたページ (->オリジナル) /