* 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
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 25f12fc..5c7345d 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -293,6 +293,21 @@
return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
}
+static long
+string_hash(a)
+ stringobject *a;
+{
+ register int len = a->ob_size;
+ register unsigned char *p = (unsigned char *) a->ob_sval;
+ register long x = *p << 7;
+ while (--len >= 0)
+ x = (x + x + x) ^ *p++;
+ x ^= a->ob_size;
+ if (x == -1)
+ x = -2;
+ return x;
+}
+
static sequence_methods string_as_sequence = {
string_length, /*sq_length*/
string_concat, /*sq_concat*/
@@ -318,6 +333,7 @@
0, /*tp_as_number*/
&string_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ string_hash, /*tp_hash*/
};
void