summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-11-05 10:20:10 (GMT)
committerGuido van Rossum <guido@python.org>1993-11-05 10:20:10 (GMT)
commit2e8f8a398e135ce4ec235c33eb64c29e6b6114ea (patch)
tree8fdd01414159567f4ce55bf31d701347a5e83e5c /Objects
parent4199facacd002fdaa2aa9c00d3bc81f9b8569862 (diff)
downloadcpython-2e8f8a398e135ce4ec235c33eb64c29e6b6114ea.zip
cpython-2e8f8a398e135ce4ec235c33eb64c29e6b6114ea.tar.gz
cpython-2e8f8a398e135ce4ec235c33eb64c29e6b6114ea.tar.bz2
Added compare operations for functions and code objects.
(Also hash, but it doesn't work yet.)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/funcobject.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index cf08af7..4dc0b90 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -106,6 +106,27 @@ func_repr(op)
return newstringobject(buf);
}
+static int
+func_compare(f, g)
+ funcobject *f, *g;
+{
+ if (f->func_globals != g->func_globals)
+ return (f->func_globals < g->func_globals) ? -1 : 1;
+ return cmpobject(f->func_code, g->func_code);
+}
+
+static long
+func_hash(f)
+ funcobject *f;
+{
+ long h;
+ h = hashobject(f->func_code);
+ if (h == -1) return h;
+ h = h ^ (long)f->func_globals;
+ if (h == -1) h = -2;
+ return h;
+}
+
typeobject Functype = {
OB_HEAD_INIT(&Typetype)
0,
@@ -116,6 +137,10 @@ typeobject Functype = {
0, /*tp_print*/
func_getattr, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ func_compare, /*tp_compare*/
func_repr, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ func_hash, /*tp_hash*/
};