diff options
| author | Neal Norwitz <nnorwitz@gmail.com> | 2003-02-02 19:59:59 (GMT) |
|---|---|---|
| committer | Neal Norwitz <nnorwitz@gmail.com> | 2003-02-02 19:59:59 (GMT) |
| commit | e8c4f9457e45f46c01acd045cc41f7364685c028 (patch) | |
| tree | 7c2b3257f9b1ff9fa418d5052704634c1260014e /Objects | |
| parent | 5a245e4d13c098cf5d846584869440f51155dbee (diff) | |
| download | cpython-e8c4f9457e45f46c01acd045cc41f7364685c028.zip cpython-e8c4f9457e45f46c01acd045cc41f7364685c028.tar.gz cpython-e8c4f9457e45f46c01acd045cc41f7364685c028.tar.bz2 | |
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.
Diffstat (limited to 'Objects')
| -rw-r--r-- | Objects/typeobject.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fa25598..ad30f8e 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3113,26 +3113,29 @@ SLOT0(slot_nb_absolute, "__abs__") static int slot_nb_nonzero(PyObject *self) { - PyObject *func, *res; + PyObject *func, *args; static PyObject *nonzero_str, *len_str; + int result = -1; func = lookup_maybe(self, "__nonzero__", &nonzero_str); if (func == NULL) { if (PyErr_Occurred()) return -1; func = lookup_maybe(self, "__len__", &len_str); - if (func == NULL) { - if (PyErr_Occurred()) - return -1; - else - return 1; + 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); } } - res = PyObject_CallObject(func, NULL); Py_DECREF(func); - if (res == NULL) - return -1; - return PyObject_IsTrue(res); + return result; } SLOT0(slot_nb_invert, "__invert__") |
