summaryrefslogtreecommitdiffstats
path: root/Objects/methodobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-03-29 10:43:31 (GMT)
committerGuido van Rossum <guido@python.org>1993-03-29 10:43:31 (GMT)
commit9bfef44d97d1ae24e03717e3d59024b44626a9de (patch)
tree736b9f406d27f9dc4496f103cd395fb7a97401d4 /Objects/methodobject.c
parent4b1302bd1d211881178618aa8f41fa4460180f2e (diff)
downloadcpython-9bfef44d97d1ae24e03717e3d59024b44626a9de.zip
cpython-9bfef44d97d1ae24e03717e3d59024b44626a9de.tar.gz
cpython-9bfef44d97d1ae24e03717e3d59024b44626a9de.tar.bz2
* Changed all copyright messages to include 1993.
* Stubs for faster implementation of local variables (not yet finished) * Added function name to code object. Print it for code and function objects. THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version number has changed accordingly) * Print address of self for built-in methods * New internal functions getattro and setattro (getattr/setattr with string object arg) * Replaced "dictobject" with more powerful "mappingobject" * New per-type functio tp_hash to implement arbitrary object hashing, and hashobject() to interface to it * Added built-in functions hash(v) and hasattr(v, 'name') * classobject: made some functions static that accidentally weren't; added __hash__ special instance method to implement hash() * Added proper comparison for built-in methods and functions
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r--Objects/methodobject.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index d0b29c7..d7ba02e 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -1,6 +1,6 @@
/***********************************************************
-Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
-Netherlands.
+Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
All Rights Reserved
@@ -108,11 +108,41 @@ meth_repr(m)
sprintf(buf, "<built-in function '%.80s'>", m->m_name);
else
sprintf(buf,
- "<built-in method '%.80s' of some %.80s object>",
- m->m_name, m->m_self->ob_type->tp_name);
+ "<built-in method '%.80s' of %.80s object at %lx>",
+ m->m_name, m->m_self->ob_type->tp_name,
+ (long)m->m_self);
return newstringobject(buf);
}
+static int
+meth_compare(a, b)
+ methodobject *a, *b;
+{
+ if (a->m_self != b->m_self)
+ return cmpobject(a->m_self, b->m_self);
+ if (a->m_meth == b->m_meth)
+ return 0;
+ if (strcmp(a->m_name, b->m_name) < 0)
+ return -1;
+ else
+ return 1;
+}
+
+static long
+meth_hash(a)
+ methodobject *a;
+{
+ long x, y;
+ if (a->m_self == NULL)
+ x = 0;
+ else {
+ x = hashobject(a->m_self);
+ if (x == -1)
+ return -1;
+ }
+ return x ^ (long) a->m_meth;
+}
+
typeobject Methodtype = {
OB_HEAD_INIT(&Typetype)
0,
@@ -123,11 +153,12 @@ typeobject Methodtype = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ meth_compare, /*tp_compare*/
meth_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ meth_hash, /*tp_hash*/
};
object *listmethods PROTO((struct methodlist *)); /* Forward */