File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -522,6 +522,7 @@ static int
522522default_3way_compare (PyObject * v , PyObject * w )
523523{
524524 int c ;
525+ char * vname , * wname ;
525526
526527 if (v -> ob_type == w -> ob_type ) {
527528 /* When comparing these pointers, they must be cast to
@@ -550,8 +551,22 @@ default_3way_compare(PyObject *v, PyObject *w)
550551 }
551552
552553 /* different type: compare type names */
553- c = strcmp (v -> ob_type -> tp_name , w -> ob_type -> tp_name );
554- return (c < 0 ) ? -1 : (c > 0 ) ? 1 : 0 ;
554+ if (v -> ob_type -> tp_as_number )
555+ vname = "" ;
556+ else
557+ vname = v -> ob_type -> tp_name ;
558+ if (w -> ob_type -> tp_as_number )
559+ wname = "" ;
560+ else
561+ wname = w -> ob_type -> tp_name ;
562+ c = strcmp (vname , wname );
563+ if (c < 0 )
564+ return -1 ;
565+ if (c > 0 )
566+ return 1 ;
567+ /* Same type name, or (more likely) incomparable numeric types */
568+ return ((Py_uintptr_t )(v -> ob_type ) < (
569+ Py_uintptr_t )(w -> ob_type )) ? -1 : 1 ;
555570}
556571
557572#define CHECK_TYPES (o ) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_CHECKTYPES)
You can’t perform that action at this time.
0 commit comments