summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-03-29 10:43:31 (GMT)
committerGuido van Rossum <guido@python.org>1993-03-29 10:43:31 (GMT)
commit9bfef44d97d1ae24e03717e3d59024b44626a9de (patch)
tree736b9f406d27f9dc4496f103cd395fb7a97401d4 /Objects/intobject.c
parent4b1302bd1d211881178618aa8f41fa4460180f2e (diff)
downloadcpython-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/intobject.c')
-rw-r--r--Objects/intobject.c32
1 files changed, 20 insertions, 12 deletions
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 @@ int_compare(v, w)
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 @@ int_or(v, w)
static object *
int_int(v)
- object *v;
+ intobject *v;
{
INCREF(v);
return v;
@@ -421,26 +431,24 @@ int_int(v)
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 @@ int_oct(v)
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 @@ int_hex(v)
return newstringobject(buf);
}
-
static number_methods int_as_number = {
int_add, /*nb_add*/
int_sub, /*nb_subtract*/
@@ -505,4 +512,5 @@ typeobject Inttype = {
&int_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ &int_hash, /*tp_hash*/
};