diff options
author | Guido van Rossum <guido@python.org> | 1993-03-29 10:43:31 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-03-29 10:43:31 (GMT) |
commit | 9bfef44d97d1ae24e03717e3d59024b44626a9de (patch) | |
tree | 736b9f406d27f9dc4496f103cd395fb7a97401d4 /Objects/longobject.c | |
parent | 4b1302bd1d211881178618aa8f41fa4460180f2e (diff) | |
download | cpython-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/longobject.c')
-rw-r--r-- | Objects/longobject.c | 32 |
1 files changed, 32 insertions, 0 deletions
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 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*/ }; |