[Python-checkins] python/nondist/sandbox/twister _random.c,1.4,1.5

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
2002年12月25日 15:48:07 -0800


Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv12876
Modified Files:
	_random.c 
Log Message:
Plugged three leaks.
Still looking for the crasher.
Narrowed it down to random_new.
Index: _random.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/_random.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** _random.c	25 Dec 2002 21:01:04 -0000	1.4
--- _random.c	25 Dec 2002 23:48:04 -0000	1.5
***************
*** 140,144 ****
 
 /* initializes mt[N] with a seed */
! static PyObject *
 init_genrand(RandomObject *self, unsigned long s)
 {
--- 140,144 ----
 
 /* initializes mt[N] with a seed */
! static void
 init_genrand(RandomObject *self, unsigned long s)
 {
***************
*** 146,150 ****
 	unsigned long *mt;
 
- 	assert(RandomObject_Check(self));
 	mt = self->state;
 	mt[0]= s & 0xffffffffUL;
--- 146,149 ----
***************
*** 160,165 ****
 	}
 	self->index = mti;
! 	Py_INCREF(Py_None);
! 	return Py_None;
 }
 
--- 159,163 ----
 	}
 	self->index = mti;
! 	return;
 }
 
***************
*** 221,225 ****
 	if (arg == NULL || arg == Py_None) {
 		time(&now);
! 		return init_genrand(self, (unsigned long)now);
 	}
 
--- 219,225 ----
 	if (arg == NULL || arg == Py_None) {
 		time(&now);
! 		init_genrand(self, (unsigned long)now);
! 		Py_INCREF(Py_None);
! 		return Py_None;
 	}
 
***************
*** 249,255 ****
 		assert(PyLong_Check(little));
 		err = PyList_Append(split, little);
 		if (err == -1)
 			goto Done;
- 		little = NULL;
 		newarg = PyNumber_Rshift(arg, thirtytwo);
 		if (newarg == NULL)
--- 249,255 ----
 		assert(PyLong_Check(little));
 		err = PyList_Append(split, little);
+ 		Py_XDECREF(little);
 		if (err == -1)
 			goto Done;
 		newarg = PyNumber_Rshift(arg, thirtytwo);
 		if (newarg == NULL)
***************
*** 279,283 ****
 	Py_XDECREF(masklower);
 	Py_XDECREF(thirtytwo);
- 	Py_XDECREF(little);
 	Py_DECREF(arg);
 	Py_DECREF(split);
--- 279,282 ----
***************
*** 378,384 ****
 	unsigned long *mt, tmp;
 
- 	assert(RandomObject_Check(self));
 	mt = self->state;
- 
 	for (i=N-1 ; i>1 ; i--) {
 		iobj = PyInt_FromLong(i);
--- 377,381 ----
***************
*** 408,418 ****
 {
 	RandomObject *self;
 	self = (RandomObject *)type->tp_alloc(type, 0);
 	if (self == NULL)
 		return NULL;
! 	if (random_seed(self, args) == NULL) {
 		Py_DECREF(self);
 		return NULL;
 	}
 	return (PyObject *)self;
 }
--- 405,419 ----
 {
 	RandomObject *self;
+ 	PyObject *tmp;
+ 
 	self = (RandomObject *)type->tp_alloc(type, 0);
 	if (self == NULL)
 		return NULL;
! 	tmp = random_seed(self, args);
! 	if (tmp == NULL) {
 		Py_DECREF(self);
 		return NULL;
 	}
+ 	Py_DECREF(tmp);
 	return (PyObject *)self;
 }

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