From: Finn B. <bc...@us...> - 2001-03-05 19:53:59
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv2925 Modified Files: PyObject.java Log Message: _cmp(): Enable a 3way compare to use the rich-compare is available. _cmp_unsafe(): Make None compare less than everything else. Index: PyObject.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyObject.java,v retrieving revision 2.22 retrieving revision 2.23 diff -C2 -r2.22 -r2.23 *** PyObject.java 2001/03/04 18:04:31 2.22 --- PyObject.java 2001/03/05 19:55:34 2.23 *************** *** 918,941 **** * @return -1 if this < 0; 0 if this == o; +1 if this > o **/ ! public final int _cmp(PyObject o2_in) { ThreadState ts = Py.getThreadState(); try { if (++ts.compareStateNesting > 500) { ! PyDictionary stateDict = ts.getCompareStateDict(); ! ! PyObject pair = make_pair(o2_in); ! ! if (stateDict.__finditem__(pair) != null) { ! // already comparing these objects. assume ! // they're equal until shown otherwise */ return 0; - } - stateDict.__setitem__(pair, pair); - int res = _cmp_unsafe(o2_in); - stateDict.__delitem__(pair); - return res; } ! return _cmp_unsafe(o2_in); } finally { ts.compareStateNesting--; } --- 918,955 ---- * @return -1 if this < 0; 0 if this == o; +1 if this > o **/ ! public final int _cmp(PyObject o) { ! PyObject token = null; ThreadState ts = Py.getThreadState(); try { if (++ts.compareStateNesting > 500) { ! if ((token = check_recursion(ts, this, o)) == null) return 0; } ! ! PyObject r; ! r = __eq__(o); ! if (r != null && r.__nonzero__()) ! return 0; ! r = o.__eq__(this); ! if (r != null && r.__nonzero__()) ! return 0; ! ! r = __lt__(o); ! if (r != null && r.__nonzero__()) ! return -1; ! r = o.__gt__(this); ! if (r != null && r.__nonzero__()) ! return -1; ! ! r = __gt__(o); ! if (r != null && r.__nonzero__()) ! return 1; ! r = o.__lt__(this); ! if (r != null && r.__nonzero__()) ! return 1; ! ! return _cmp_unsafe(o); } finally { + delete_token(ts, token); ts.compareStateNesting--; } *************** *** 972,976 **** } else ctmp = null; - if (ctmp != Py.None && (itmp = o1.__cmp__(o2)) != -2) return itmp; --- 986,989 ---- *************** *** 995,998 **** --- 1008,1017 ---- if (this == o2_in) return 0; + + /* None is smaller than anything */ + if (this == Py.None) + return -1; + if (o2_in == Py.None) + return 1; // No rational way to compare these, so ask their classes to compare |