[Python-checkins] python/dist/src/Objects typeobject.c,2.195,2.196
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 07 Dec 2002 13:39:19 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv14618/python/Objects
Modified Files:
typeobject.c
Log Message:
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.
Bugfix candidate.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.195
retrieving revision 2.196
diff -C2 -d -r2.195 -r2.196
*** typeobject.c 6 Dec 2002 23:38:02 -0000 2.195
--- typeobject.c 7 Dec 2002 21:39:16 -0000 2.196
***************
*** 44,48 ****
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
etype* et = (etype*)type;
!
Py_INCREF(et->name);
return et->name;
--- 44,48 ----
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
etype* et = (etype*)type;
!
Py_INCREF(et->name);
return et->name;
***************
*** 79,83 ****
return -1;
}
! if (strlen(PyString_AS_STRING(value))
!= (size_t)PyString_GET_SIZE(value)) {
PyErr_Format(PyExc_ValueError,
--- 79,83 ----
return -1;
}
! if (strlen(PyString_AS_STRING(value))
!= (size_t)PyString_GET_SIZE(value)) {
PyErr_Format(PyExc_ValueError,
***************
*** 311,318 ****
type->tp_base = old_base;
type->tp_mro = old_mro;
!
Py_DECREF(value);
Py_DECREF(new_base);
!
return -1;
}
--- 311,318 ----
type->tp_base = old_base;
type->tp_mro = old_mro;
!
Py_DECREF(value);
Py_DECREF(new_base);
!
return -1;
}
***************
*** 885,903 ****
}
! /*
Method resolution order algorithm C3 described in
"A Monotonic Superclass Linearization for Dylan",
by Kim Barrett, Bob Cassel, Paul Haahr,
! David A. Moon, Keith Playford, and P. Tucker Withington.
(OOPSLA 1996)
Some notes about the rules implied by C3:
! No duplicate bases.
It isn't legal to repeat a class in a list of base classes.
The next three properties are the 3 constraints in "C3".
! Local precendece order.
If A precedes B in C's MRO, then A will precede B in the MRO of all
subclasses of C.
--- 885,903 ----
}
! /*
Method resolution order algorithm C3 described in
"A Monotonic Superclass Linearization for Dylan",
by Kim Barrett, Bob Cassel, Paul Haahr,
! David A. Moon, Keith Playford, and P. Tucker Withington.
(OOPSLA 1996)
Some notes about the rules implied by C3:
! No duplicate bases.
It isn't legal to repeat a class in a list of base classes.
The next three properties are the 3 constraints in "C3".
! Local precendece order.
If A precedes B in C's MRO, then A will precede B in the MRO of all
subclasses of C.
***************
*** 913,917 ****
*/
! static int
tail_contains(PyObject *list, int whence, PyObject *o) {
int j, size;
--- 913,917 ----
*/
! static int
tail_contains(PyObject *list, int whence, PyObject *o) {
int j, size;
***************
*** 1011,1020 ****
}
! static int
pmerge(PyObject *acc, PyObject* to_merge) {
int i, j, to_merge_size;
int *remain;
int ok, empty_cnt;
!
to_merge_size = PyList_GET_SIZE(to_merge);
--- 1011,1020 ----
}
! static int
pmerge(PyObject *acc, PyObject* to_merge) {
int i, j, to_merge_size;
int *remain;
int ok, empty_cnt;
!
to_merge_size = PyList_GET_SIZE(to_merge);
***************
*** 1033,1037 ****
for (i = 0; i < to_merge_size; i++) {
PyObject *candidate;
!
PyObject *cur_list = PyList_GET_ITEM(to_merge, i);
--- 1033,1037 ----
for (i = 0; i < to_merge_size; i++) {
PyObject *candidate;
!
PyObject *cur_list = PyList_GET_ITEM(to_merge, i);
***************
*** 1093,1097 ****
/* Find a superclass linearization that honors the constraints
of the explicit lists of bases and the constraints implied by
! each base class.
to_merge is a list of lists, where each list is a superclass
--- 1093,1097 ----
/* Find a superclass linearization that honors the constraints
of the explicit lists of bases and the constraints implied by
! each base class.
to_merge is a list of lists, where each list is a superclass
***************
*** 2289,2293 ****
return 0;
}
!
return 1;
}
--- 2289,2293 ----
return 0;
}
!
return 1;
}
***************
*** 2356,2360 ****
static PyMethodDef object_methods[] = {
! {"__reduce__", object_reduce, METH_NOARGS,
PyDoc_STR("helper for pickle")},
{0}
--- 2356,2360 ----
static PyMethodDef object_methods[] = {
! {"__reduce__", object_reduce, METH_NOARGS,
PyDoc_STR("helper for pickle")},
{0}
***************
*** 3735,3740 ****
slot_nb_nonzero(PyObject *self)
{
! PyObject *func, *res, *args;
static PyObject *nonzero_str, *len_str;
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
--- 3735,3741 ----
slot_nb_nonzero(PyObject *self)
{
! PyObject *func, *args;
static PyObject *nonzero_str, *len_str;
+ int result = -1;
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
***************
*** 3743,3762 ****
return -1;
func = lookup_maybe(self, "__len__", &len_str);
! if (func == NULL) {
! if (PyErr_Occurred())
! return -1;
! else
! return 1;
! }
! }
! args = res = PyTuple_New(0);
if (args != NULL) {
! res = PyObject_Call(func, args, NULL);
Py_DECREF(args);
}
Py_DECREF(func);
! if (res == NULL)
! return -1;
! return PyObject_IsTrue(res);
}
--- 3744,3761 ----
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;
}