]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport fix to SF bug #820397: __nonzero__() returns 1/0
authorRaymond Hettinger <python@rcn.com>
Sun, 12 Oct 2003 23:41:21 +0000 (23:41 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 12 Oct 2003 23:41:21 +0000 (23:41 +0000)
Objects/typeobject.c

index b07ce2e6fe20cf2a0e549da5668d9e153b5a36a3..2d8b9db078716d4119d75a5304ee87302c08e079 100644 (file)
@@ -3311,6 +3311,20 @@ wrap_inquiry(PyObject *self, PyObject *args, void *wrapped)
        return PyInt_FromLong((long)res);
 }
 
+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)
 {
@@ -4900,7 +4914,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, "<<"),