#17890: Remove _(rich)cmp_c_impl
-------------------------------------+-------------------------------------
       Reporter:  jdemeyer           |        Owner:
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.6
      Component:  cython             |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Jeroen Demeyer     |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/jdemeyer/ticket/17890            |  17bd067153ad40ced061147390687f514a7f7cba
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by jdemeyer):

 This is how Python implements `cmp`:
 {{{
 #!c
 static int
 do_cmp(PyObject *v, PyObject *w)
 {
     int c;
     cmpfunc f;

     if (v->ob_type == w->ob_type
         && (f = v->ob_type->tp_compare) != NULL) {
         c = (*f)(v, w);
         if (PyInstance_Check(v)) {
             /* Instance tp_compare has a different signature.
                But if it returns undefined we fall through. */
             if (c != 2)
                 return c;
             /* Else fall through to try_rich_to_3way_compare() */
         }
         else
             return adjust_tp_compare(c);
     }
     /* We only get here if one of the following is true:
        a) v and w have different types
        b) v and w have the same type, which doesn't have tp_compare
        c) v and w are instances, and either __cmp__ is not defined or
           __cmp__ returns NotImplemented
     */
     c = try_rich_to_3way_compare(v, w);
     if (c < 2)
         return c;
     c = try_3way_compare(v, w);
     if (c < 2)
         return c;
     return default_3way_compare(v, w);
 }
 }}}

 Note how `tp_compare` is only called if the types of `v` and `w` are
 equal. If not, `__richcmp__` is used. Only if `__richcmp__` is not
 implemented, then `__cmp__` is tried after all.

--
Ticket URL: <http://trac.sagemath.org/ticket/17890#comment:42>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to