* 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/longobject.c b/Objects/longobject.c
index 38473e2..fb82a1f 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -555,6 +555,7 @@
static int long_print PROTO((object *, FILE *, int));
static object *long_repr PROTO((object *));
static int long_compare PROTO((longobject *, longobject *));
+static long long_hash PROTO((longobject *));
static object *long_add PROTO((longobject *, longobject *));
static object *long_sub PROTO((longobject *, longobject *));
@@ -615,6 +616,35 @@
return sign < 0 ? -1 : sign > 0 ? 1 : 0;
}
+static long
+long_hash(v)
+ longobject *v;
+{
+ long x;
+ int i, sign;
+
+ /* This is designed so that Python ints and longs with the
+ same value hash to the same value, otherwise comparisons
+ of mapping keys will turn out weird */
+ i = v->ob_size;
+ sign = 1;
+ x = 0;
+ if (i < 0) {
+ sign = -1;
+ i = -(i);
+ }
+ while (--i >= 0) {
+ /* Force a 32-bit circular shift */
+ x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) & MASK);
+ x += v->ob_digit[i];
+ }
+ x = x * sign;
+ if (x == -1)
+ x = -2;
+ return x;
+}
+
+
/* Add the absolute values of two long integers. */
static longobject *x_add PROTO((longobject *, longobject *));
@@ -1346,4 +1376,6 @@
&long_as_number,/*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ (long (*) FPROTO((object *)))
+ long_hash, /*tp_hash*/
};