diff Objects/typeobject.c @ 30685:6c38406c3fad 2.3

Backport fix to SF bug #820397: __nonzero__() returns 1/0
author Raymond Hettinger <python@rcn.com>
date Sun, 12 Oct 2003 23:41:21 +0000
parents 6ef245136038
children 6f15e73b59f2
line wrap: on
line diff
--- a/Objects/typeobject.c	Sun Oct 12 02:03:06 2003 +0000
+++ b/Objects/typeobject.c	Sun Oct 12 23:41:21 2003 +0000
@@ -3312,6 +3312,20 @@
 }
 
 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;
@@ -4900,7 +4914,7 @@
 	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, "<<"),