summaryrefslogtreecommitdiff
path: root/Objects/methodobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r--Objects/methodobject.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index ecc9a0ab52..862acd1f5c 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -196,17 +196,31 @@ meth_repr(PyCFunctionObject *m)
m->m_self);
}
-static int
-meth_compare(PyCFunctionObject *a, PyCFunctionObject *b)
+static PyObject *
+meth_richcompare(PyObject *self, PyObject *other, int op)
{
- if (a->m_self != b->m_self)
- return (a->m_self < b->m_self) ? -1 : 1;
- if (a->m_ml->ml_meth == b->m_ml->ml_meth)
- return 0;
- if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0)
- return -1;
+ PyCFunctionObject *a, *b;
+ PyObject *res;
+ int eq;
+
+ if ((op != Py_EQ && op != Py_NE) ||
+ !PyCFunction_Check(self) ||
+ !PyCFunction_Check(other))
+ {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ a = (PyCFunctionObject *)self;
+ b = (PyCFunctionObject *)other;
+ eq = a->m_self == b->m_self;
+ if (eq)
+ eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
+ if (op == Py_EQ)
+ res = eq ? Py_True : Py_False;
else
- return 1;
+ res = eq ? Py_False : Py_True;
+ Py_INCREF(res);
+ return res;
}
static long
@@ -240,7 +254,7 @@ PyTypeObject PyCFunction_Type = {
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- (cmpfunc)meth_compare, /* tp_compare */
+ 0, /* tp_compare */
(reprfunc)meth_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -255,7 +269,7 @@ PyTypeObject PyCFunction_Type = {
0, /* tp_doc */
(traverseproc)meth_traverse, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ meth_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */