diff options
author | Raymond Hettinger <python@rcn.com> | 2003-10-11 17:29:04 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-10-11 17:29:04 (GMT) |
commit | f34f2646a140c4b59ffcdeb7b55e61962b8bc249 (patch) | |
tree | 48dc156427c46742ef3cab7e49acd31865116756 | |
parent | 40b9df2feaa48f36f70ae1888e303f03ade11dae (diff) | |
download | cpython-f34f2646a140c4b59ffcdeb7b55e61962b8bc249.zip cpython-f34f2646a140c4b59ffcdeb7b55e61962b8bc249.tar.gz cpython-f34f2646a140c4b59ffcdeb7b55e61962b8bc249.tar.bz2 |
SF bug #820397: __nonzero__() returns 1/0
Altered to return a PyBool instead of a PyInt.
Backport candidate.
-rw-r--r-- | Objects/typeobject.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index cc844ad..945c337 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3326,6 +3326,20 @@ wrap_inquiry(PyObject *self, PyObject *args, void *wrapped) } static PyObject * +wrap_inquirypred(PyObject *self, PyObject *args, void *wrapped) +{ + inquiry func = (inquiry)wrapped; + int res; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + res = (*func)(self); + if (res == -1 && PyErr_Occurred()) + return NULL; + return PyBool_FromLong((long)res); +} + +static PyObject * wrap_binaryfunc(PyObject *self, PyObject *args, void *wrapped) { binaryfunc func = (binaryfunc)wrapped; @@ -4914,7 +4928,7 @@ static slotdef slotdefs[] = { UNSLOT("__pos__", nb_positive, slot_nb_positive, wrap_unaryfunc, "+x"), UNSLOT("__abs__", nb_absolute, slot_nb_absolute, wrap_unaryfunc, "abs(x)"), - UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_inquiry, + UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_inquirypred, "x != 0"), UNSLOT("__invert__", nb_invert, slot_nb_invert, wrap_unaryfunc, "~x"), BINSLOT("__lshift__", nb_lshift, slot_nb_lshift, "<<"), |