summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-02-01 12:13:56 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-02-01 12:13:56 (GMT)
commitf02e0aaafd2476948047f0ce904af947f02d18ea (patch)
tree724366997190a0acf829f65a4f1e96d82c060889 /Objects
parent211c6258294bf683935bff73a61ce3dd84070988 (diff)
downloadcpython-f02e0aaafd2476948047f0ce904af947f02d18ea.zip
cpython-f02e0aaafd2476948047f0ce904af947f02d18ea.tar.gz
cpython-f02e0aaafd2476948047f0ce904af947f02d18ea.tar.bz2
Issue #1717: remove the cmp builtin function, the C-API functions
PyObject_Cmp, PyObject_Compare, and various support functions.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c16
-rw-r--r--Objects/object.c100
-rw-r--r--Objects/typeobject.c2
3 files changed, 1 insertions, 117 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 1f988ec..e42008a 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -27,22 +27,6 @@ null_error(void)
/* Operations on any object */
-int
-PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)
-{
- int r;
-
- if (o1 == NULL || o2 == NULL) {
- null_error();
- return -1;
- }
- r = PyObject_Compare(o1, o2);
- if (PyErr_Occurred())
- return -1;
- *result = r;
- return 0;
-}
-
PyObject *
PyObject_Type(PyObject *o)
{
diff --git a/Objects/object.c b/Objects/object.c
index 00657de..85dbd28 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -549,68 +549,6 @@ PyObject_Bytes(PyObject *v)
*/
-/* Forward */
-static PyObject *do_richcompare(PyObject *v, PyObject *w, int op);
-
-/* Perform a three-way comparison, raising TypeError if three-way comparison
- is not supported. */
-static int
-do_compare(PyObject *v, PyObject *w)
-{
- cmpfunc f;
- int ok;
-
- if (v->ob_type == w->ob_type &&
- (f = v->ob_type->tp_compare) != NULL) {
- return (*f)(v, w);
- }
-
- /* Now try three-way compare before giving up. This is intentionally
- elaborate; if you have a it will raise TypeError if it detects two
- objects that aren't ordered with respect to each other. */
- ok = PyObject_RichCompareBool(v, w, Py_LT);
- if (ok < 0)
- return -1; /* Error */
- if (ok)
- return -1; /* Less than */
- ok = PyObject_RichCompareBool(v, w, Py_GT);
- if (ok < 0)
- return -1; /* Error */
- if (ok)
- return 1; /* Greater than */
- ok = PyObject_RichCompareBool(v, w, Py_EQ);
- if (ok < 0)
- return -1; /* Error */
- if (ok)
- return 0; /* Equal */
-
- /* Give up */
- PyErr_Format(PyExc_TypeError,
- "unorderable types: '%.100s' != '%.100s'",
- v->ob_type->tp_name,
- w->ob_type->tp_name);
- return -1;
-}
-
-/* Perform a three-way comparison. This wraps do_compare() with a check for
- NULL arguments and a recursion check. */
-int
-PyObject_Compare(PyObject *v, PyObject *w)
-{
- int res;
-
- if (v == NULL || w == NULL) {
- if (!PyErr_Occurred())
- PyErr_BadInternalCall();
- return -1;
- }
- if (Py_EnterRecursiveCall(" in cmp"))
- return -1;
- res = do_compare(v, w);
- Py_LeaveRecursiveCall();
- return res < 0 ? -1 : res;
-}
-
/* Map rich comparison operators to their swapped version, e.g. LT <--> GT */
int _Py_SwappedOp[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
@@ -715,44 +653,6 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
return ok;
}
-/* Turn the result of a three-way comparison into the result expected by a
- rich comparison. */
-PyObject *
-Py_CmpToRich(int op, int cmp)
-{
- PyObject *res;
- int ok;
-
- if (PyErr_Occurred())
- return NULL;
- switch (op) {
- case Py_LT:
- ok = cmp < 0;
- break;
- case Py_LE:
- ok = cmp <= 0;
- break;
- case Py_EQ:
- ok = cmp == 0;
- break;
- case Py_NE:
- ok = cmp != 0;
- break;
- case Py_GT:
- ok = cmp > 0;
- break;
- case Py_GE:
- ok = cmp >= 0;
- break;
- default:
- PyErr_BadArgument();
- return NULL;
- }
- res = ok ? Py_True : Py_False;
- Py_INCREF(res);
- return res;
-}
-
/* Set of hash utility functions to help maintaining the invariant that
if a==b then hash(a)==hash(b)
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index b2ad89f..3f1df8d 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2897,7 +2897,7 @@ same_slots_added(PyTypeObject *a, PyTypeObject *b)
slots_a = ((PyHeapTypeObject *)a)->ht_slots;
slots_b = ((PyHeapTypeObject *)b)->ht_slots;
if (slots_a && slots_b) {
- if (PyObject_Compare(slots_a, slots_b) != 0)
+ if (PyObject_RichCompareBool(slots_a, slots_b, Py_EQ) != 1)
return 0;
size += sizeof(PyObject *) * PyTuple_GET_SIZE(slots_a);
}