[Python-checkins] python/dist/src/Objects typeobject.c,2.126.4.31,2.126.4.32

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Sun, 02 Feb 2003 12:00:03 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv8324/Objects

Modified Files:
      Tag: release22-maint
	typeobject.c 
Log Message:
backport:

revision 2.196
date: 2002/12/07 21:39:16;  author: tim_one;  state: Exp;  lines: +27 -28
slot_nb_nonzero():  Another leak uncovered by the sandbox datetime
tests.  I found the logic too confusing to follow here, so rewrote more
than was likely absolutely necessary.



Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.126.4.31
retrieving revision 2.126.4.32
diff -C2 -d -r2.126.4.31 -r2.126.4.32
*** typeobject.c	7 Jan 2003 21:47:44 -0000	2.126.4.31
--- typeobject.c	2 Feb 2003 19:59:59 -0000	2.126.4.32
***************
*** 3114,3119 ****
  slot_nb_nonzero(PyObject *self)
  {
! 	PyObject *func, *res;
  	static PyObject *nonzero_str, *len_str;
  
  	func = lookup_maybe(self, "__nonzero__", &nonzero_str);
--- 3114,3120 ----
  slot_nb_nonzero(PyObject *self)
  {
! 	PyObject *func, *args;
  	static PyObject *nonzero_str, *len_str;
+ 	int result = -1;
  
  	func = lookup_maybe(self, "__nonzero__", &nonzero_str);
***************
*** 3122,3137 ****
  			return -1;
  		func = lookup_maybe(self, "__len__", &len_str);
! 		if (func == NULL) {
! 			if (PyErr_Occurred())
! 				return -1;
! 			else
! 				return 1;
  		}
  	}
- 	res = PyObject_CallObject(func, NULL);
  	Py_DECREF(func);
! 	if (res == NULL)
! 		return -1;
! 	return PyObject_IsTrue(res);
  }
  
--- 3123,3140 ----
  			return -1;
  		func = lookup_maybe(self, "__len__", &len_str);
! 		if (func == NULL)
! 			return PyErr_Occurred() ? -1 : 1;
! 	}
! 	args = PyTuple_New(0);
! 	if (args != NULL) {
! 		PyObject *temp = PyObject_Call(func, args, NULL);
! 		Py_DECREF(args);
! 		if (temp != NULL) {
! 			result = PyObject_IsTrue(temp);
! 			Py_DECREF(temp);
  		}
  	}
  	Py_DECREF(func);
! 	return result;
  }