summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2008-01-01 04:06:48 (GMT)
committerGuido van Rossum <guido@python.org>2008-01-01 04:06:48 (GMT)
commitf5243f07f640f4ae847f2d56e86f5b48ed78728a (patch)
tree46d447127d885a6dc3f131d724e9e52e9b617506
parenta9de06d2c55499dc6975370ecd76342660d973a2 (diff)
downloadcpython-f5243f07f640f4ae847f2d56e86f5b48ed78728a.zip
cpython-f5243f07f640f4ae847f2d56e86f5b48ed78728a.tar.gz
cpython-f5243f07f640f4ae847f2d56e86f5b48ed78728a.tar.bz2
Merge changes from 59576 from trunk to p3yk branch; these were skipped
in the regular merge. Fixes issue #1693.
-rw-r--r--Objects/typeobject.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index bf07188..982eedb 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3167,28 +3167,22 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
}
-/* Map rich comparison operators to their __xx__ namesakes */
-static char *name_op[] = {
- "__lt__",
- "__le__",
+static char *hash_name_op[] = {
"__eq__",
- "__ne__",
- "__gt__",
- "__ge__",
- /* These are only for overrides_cmp_or_hash(): */
"__cmp__",
"__hash__",
+ NULL
};
static int
-overrides_cmp_or_hash(PyTypeObject *type)
+overrides_hash(PyTypeObject *type)
{
- int i;
+ char **p;
PyObject *dict = type->tp_dict;
assert(dict != NULL);
- for (i = 0; i < 8; i++) {
- if (PyDict_GetItemString(dict, name_op[i]) != NULL)
+ for (p = hash_name_op; *p; p++) {
+ if (PyDict_GetItemString(dict, *p) != NULL)
return 1;
}
return 0;
@@ -3314,7 +3308,7 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
if (type->tp_compare == NULL &&
type->tp_richcompare == NULL &&
type->tp_hash == NULL &&
- !overrides_cmp_or_hash(type))
+ !overrides_hash(type))
{
type->tp_compare = base->tp_compare;
type->tp_richcompare = base->tp_richcompare;
@@ -4739,6 +4733,15 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value)
return 0;
}
+static char *name_op[] = {
+ "__lt__",
+ "__le__",
+ "__eq__",
+ "__ne__",
+ "__gt__",
+ "__ge__",
+};
+
static PyObject *
half_richcompare(PyObject *self, PyObject *other, int op)
{