@@ -103,6 +103,21 @@ static PyObject* wrap_richcmpfunc(richcmpfunc f, PyObject* a, PyObject* b, PyObj
103
103
return f (a , b , (int )PyLong_AsLong (n ));
104
104
}
105
105
106
+ #undef RICHCMP_WRAPPER
107
+ #define RICHCMP_WRAPPER (NAME , OP ) \
108
+ static PyObject* wrap_richcmpfunc_##NAME(richcmpfunc f, \
109
+ PyObject* a, \
110
+ PyObject* b) { \
111
+ return f(a, b, OP); \
112
+ }
113
+
114
+ RICHCMP_WRAPPER (lt , Py_LT )
115
+ RICHCMP_WRAPPER (le , Py_LE )
116
+ RICHCMP_WRAPPER (eq , Py_EQ )
117
+ RICHCMP_WRAPPER (ne , Py_NE )
118
+ RICHCMP_WRAPPER (gt , Py_GT )
119
+ RICHCMP_WRAPPER (ge , Py_GE )
120
+
106
121
static PyObject * wrap_ssizeobjargproc (ssizeobjargproc f , PyObject * a , PyObject * size , PyObject * b ) {
107
122
return PyLong_FromLong (f (a , PyLong_AsSsize_t (size ), b ));
108
123
}
@@ -315,7 +330,15 @@ int PyType_Ready(PyTypeObject* cls) {
315
330
ADD_SLOT ("__getattr__" , cls -> tp_getattro , -2 );
316
331
ADD_SLOT_CONV ("__setattr__" , wrap_setattrofunc , cls -> tp_setattro , -3 );
317
332
ADD_SLOT ("__clear__" , cls -> tp_clear , -1 );
318
- ADD_SLOT_CONV ("__compare__" , wrap_richcmpfunc , cls -> tp_richcompare , -3 );
333
+ if (cls -> tp_richcompare ) {
334
+ ADD_SLOT_CONV ("__compare__" , wrap_richcmpfunc , cls -> tp_richcompare , -3 );
335
+ ADD_SLOT_CONV ("__lt__" , wrap_richcmpfunc_lt , cls -> tp_richcompare , -2 );
336
+ ADD_SLOT_CONV ("__le__" , wrap_richcmpfunc_le , cls -> tp_richcompare , -2 );
337
+ ADD_SLOT_CONV ("__eq__" , wrap_richcmpfunc_eq , cls -> tp_richcompare , -2 );
338
+ ADD_SLOT_CONV ("__ne__" , wrap_richcmpfunc_ne , cls -> tp_richcompare , -2 );
339
+ ADD_SLOT_CONV ("__gt__" , wrap_richcmpfunc_gt , cls -> tp_richcompare , -2 );
340
+ ADD_SLOT_CONV ("__ge__" , wrap_richcmpfunc_ge , cls -> tp_richcompare , -2 );
341
+ }
319
342
ADD_SLOT ("__iter__" , cls -> tp_iter , -1 );
320
343
ADD_SLOT ("__next__" , cls -> tp_iternext , -1 );
321
344
ADD_SLOT ("__get__" , cls -> tp_descr_get , -3 );
0 commit comments