* 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/intobject.c b/Objects/intobject.c
index 858458c..6806f0c 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -144,6 +144,16 @@
return (i < j) ? -1 : (i > j) ? 1 : 0;
}
+static long
+int_hash(v)
+ intobject *v;
+{
+ long x = v -> ob_ival;
+ if (x == -1)
+ x = -2;
+ return x;
+}
+
static object *
int_add(v, w)
intobject *v;
@@ -413,7 +423,7 @@
static object *
int_int(v)
- object *v;
+ intobject *v;
{
INCREF(v);
return v;
@@ -421,26 +431,24 @@
static object *
int_long(v)
- object *v;
+ intobject *v;
{
- long x = getintvalue(v);
- return newlongobject(x);
+ return newlongobject((v -> ob_ival));
}
static object *
int_float(v)
- object *v;
+ intobject *v;
{
- long x = getintvalue(v);
- return newfloatobject((double)x);
+ return newfloatobject((double)(v -> ob_ival));
}
static object *
int_oct(v)
- object *v;
+ intobject *v;
{
char buf[20];
- long x = getintvalue(v);
+ long x = v -> ob_ival;
if (x == 0)
strcpy(buf, "0");
else if (x > 0)
@@ -452,10 +460,10 @@
static object *
int_hex(v)
- object *v;
+ intobject *v;
{
char buf[20];
- long x = getintvalue(v);
+ long x = v -> ob_ival;
if (x >= 0)
sprintf(buf, "0x%lx", x);
else
@@ -463,7 +471,6 @@
return newstringobject(buf);
}
-
static number_methods int_as_number = {
int_add, /*nb_add*/
int_sub, /*nb_subtract*/
@@ -505,4 +512,5 @@
&int_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ &int_hash, /*tp_hash*/
};