File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -691,14 +691,36 @@ to_float(PyObject *self)
691691static PyObject *
692692richcompare (PyObject * self , PyObject * other , int op )
693693{
694- MPZ_Object * u = (MPZ_Object * )self , * v = NULL ;
694+ zz_t * u = & ((MPZ_Object * )self )-> z ;
695+ zz_ord r ;
695696
696- assert (MPZ_Check (self ));
697- CHECK_OP (v , other );
697+ if (MPZ_Check (other )) {
698+ r = zz_cmp (u , & ((MPZ_Object * )other )-> z );
699+ }
700+ else if (PyLong_Check (other )) {
701+ int32_t v ;
698702
699- zz_ord r = zz_cmp (& u -> z , & v -> z );
703+ if (PyLong_AsInt32 (other , & v ) == 0 ) {
704+ r = zz_cmp_i32 (u , v );
705+ }
706+ else {
707+ PyErr_Clear ();
700708
701- Py_DECREF (v );
709+ MPZ_Object * v = MPZ_from_int (other );
710+
711+ if (!v ) {
712+ goto end ; /* LCOV_EXCL_LINE */
713+ }
714+ r = zz_cmp (u , & v -> z );
715+ Py_DECREF (v );
716+ }
717+ }
718+ else if (Number_Check (other )) {
719+ goto numbers ;
720+ }
721+ else {
722+ goto fallback ;
723+ }
702724 switch (op ) {
703725 case Py_LT :
704726 return PyBool_FromLong (r == ZZ_LT );
You can’t perform that action at this time.
0 commit comments