[Python-checkins] python/nondist/sandbox/twister _random.c,1.17,1.18

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sun, 29 Dec 2002 00:47:47 -0800


Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv6629

Modified Files:
	_random.c 
Log Message:
random_jumpahead():  PyInt_FromLong() can fail, so check for that.
XXX This algorithm doesn't make much sense to me.  For example, no
XXX matter what value of N is passed in, N % (N-1) == 1 on the
XXX first loop trip, N % (N-2) == 2 on the second loop trip, and so
XXX on until iobj reaches N//2.


Index: _random.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/_random.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** _random.c	29 Dec 2002 08:34:29 -0000	1.17
--- _random.c	29 Dec 2002 08:47:45 -0000	1.18
***************
*** 387,392 ****
  
  	mt = self->state;
! 	for (i=N-1 ; i>1 ; i--) {
  		iobj = PyInt_FromLong(i);
  		remobj = PyNumber_Remainder(n, iobj);
  		Py_DECREF(iobj);
--- 387,394 ----
  
  	mt = self->state;
! 	for (i = N-1; i > 1; i--) {
  		iobj = PyInt_FromLong(i);
+ 		if (iobj == NULL)
+ 			return NULL;
  		remobj = PyNumber_Remainder(n, iobj);
  		Py_DECREF(iobj);
***************
*** 402,406 ****
  	}
  
! 	for (i=0 ; i<N ; i++)
  		mt[i] += i+1;
  
--- 404,408 ----
  	}
  
! 	for (i = 0; i < N; i++)
  		mt[i] += i+1;