* 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
This commit is contained in:
Guido van Rossum 1993-03-29 10:43:31 +00:00
parent 4b1302bd1d
commit 9bfef44d97
97 changed files with 559 additions and 246 deletions

View file

@ -555,6 +555,7 @@ static void long_dealloc PROTO((object *));
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 @@ long_compare(a, b)
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 @@ typeobject Longtype = {
&long_as_number,/*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
(long (*) FPROTO((object *)))
long_hash, /*tp_hash*/
};