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 /Python/bltinmodule.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 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 4213fc3..8fd12e4 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -281,10 +281,28 @@ builtin_getattr(self, args) object *args; { object *v; - char *name; - if (!getargs(args, "(Os)", &v, &name)) + object *name; + if (!getargs(args, "(OS)", &v, &name)) return NULL; - return getattr(v, name); + return getattro(v, name); +} + +static object * +builtin_hasattr(self, args) + object *self; + object *args; +{ + object *v; + object *name; + if (!getargs(args, "(OS)", &v, &name)) + return NULL; + v = getattro(v, name); + if (v == NULL) { + err_clear(); + return newintobject(0L); + } + DECREF(v); + return newintobject(1L); } static object * @@ -293,17 +311,32 @@ builtin_setattr(self, args) object *args; { object *v; - char *name; + object *name; object *value; - if (!getargs(args, "(OsO)", &v, &name, &value)) + if (!getargs(args, "(OSO)", &v, &name, &value)) return NULL; - if (setattr(v, name, value) != 0) + if (setattro(v, name, value) != 0) return NULL; INCREF(None); return None; } static object * +builtin_hash(self, args) + object *self; + object *args; +{ + object *v; + long x; + if (!getargs(args, "O", &v)) + return NULL; + x = hashobject(v); + if (x == -1) + return NULL; + return newintobject(x); +} + +static object * builtin_hex(self, v) object *self; object *v; @@ -687,6 +720,8 @@ static struct methodlist builtin_methods[] = { {"execfile", builtin_execfile}, {"float", builtin_float}, {"getattr", builtin_getattr}, + {"hasattr", builtin_hasattr}, + {"hash", builtin_hash}, {"hex", builtin_hex}, {"input", builtin_input}, {"int", builtin_int}, |