diff Objects/methodobject.c @ 1257:1cabc2b6c970 legacy-trunk

* 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
author Guido van Rossum <guido@python.org>
date Mon, 29 Mar 1993 10:43:31 +0000
parents f54e64c8b9b7
children 7971fecbf28e
line wrap: on
line diff
--- a/Objects/methodobject.c	Sat Mar 27 18:11:32 1993 +0000
+++ b/Objects/methodobject.c	Mon Mar 29 10:43:31 1993 +0000
@@ -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 @@
 		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 @@
 	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 */