mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Backport fix to SF bug #820397: __nonzero__() returns 1/0
This commit is contained in:
@@ -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, "<<"),
|
||||
|
||||
Reference in New Issue
Block a user