diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 47 | ||||
-rw-r--r-- | Python/ceval.c | 32 | ||||
-rw-r--r-- | Python/cgensupport.c | 4 | ||||
-rw-r--r-- | Python/compile.c | 43 | ||||
-rw-r--r-- | Python/fmod.c | 4 | ||||
-rw-r--r-- | Python/getcwd.c | 4 | ||||
-rw-r--r-- | Python/import.c | 4 | ||||
-rw-r--r-- | Python/marshal.c | 4 | ||||
-rw-r--r-- | Python/pythonmain.c | 4 | ||||
-rw-r--r-- | Python/pythonrun.c | 4 | ||||
-rw-r--r-- | Python/strerror.c | 4 | ||||
-rw-r--r-- | Python/structmember.c | 4 | ||||
-rw-r--r-- | Python/traceback.c | 4 |
13 files changed, 118 insertions, 44 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}, diff --git a/Python/ceval.c b/Python/ceval.c index 97f38ab..64f2429 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -173,6 +173,7 @@ eval_code(co, globals, locals, arg) register object *u; register object *t; register frameobject *f; /* Current frame */ + register listobject *fastlocals = NULL; object *trace = NULL; /* Trace function or NULL */ object *retval; /* Return value iff why == WHY_RETURN */ char *name; /* Name used by some instructions */ @@ -911,19 +912,18 @@ eval_code(co, globals, locals, arg) break; case STORE_ATTR: - name = GETNAME(oparg); + w = GETNAMEV(oparg); v = POP(); u = POP(); - err = setattr(v, name, u); /* v.name = u */ + err = setattro(v, w, u); /* v.w = u */ DECREF(v); DECREF(u); break; case DELETE_ATTR: - name = GETNAME(oparg); + w = GETNAMEV(oparg); v = POP(); - err = setattr(v, name, (object *)NULL); - /* del v.name */ + err = setattro(v, w, (object *)NULL); /* del v.w */ DECREF(v); break; @@ -992,6 +992,22 @@ eval_code(co, globals, locals, arg) INCREF(x); PUSH(x); break; + + case RESERVE_FAST: + if (oparg > 0) { + XDECREF(fastlocals); + x = newlistobject(oparg); + fastlocals = (listobject *) x; + } + break; + + case LOAD_FAST: + /* NYI */ + break; + + case STORE_FAST: + /* NYI */ + break; case BUILD_TUPLE: x = newtupleobject(oparg); @@ -1025,9 +1041,9 @@ eval_code(co, globals, locals, arg) break; case LOAD_ATTR: - name = GETNAME(oparg); + w = GETNAMEV(oparg); v = POP(); - x = getattr(v, name); + x = getattro(v, w); DECREF(v); PUSH(x); break; @@ -1283,6 +1299,8 @@ eval_code(co, globals, locals, arg) current_frame = f->f_back; DECREF(f); + + XDECREF(fastlocals); return retval; } diff --git a/Python/cgensupport.c b/Python/cgensupport.c index a3023eb..5dcac86 100644 --- a/Python/cgensupport.c +++ b/Python/cgensupport.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/compile.c b/Python/compile.c index 483e524..116b6bb 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved @@ -50,6 +50,7 @@ static struct memberlist code_memberlist[] = { {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, {"co_names", T_OBJECT, OFF(co_names), READONLY}, {"co_filename", T_OBJECT, OFF(co_filename), READONLY}, + {"co_name", T_OBJECT, OFF(co_name), READONLY}, {NULL} /* Sentinel */ }; @@ -69,6 +70,7 @@ code_dealloc(co) XDECREF(co->co_consts); XDECREF(co->co_names); XDECREF(co->co_filename); + XDECREF(co->co_name); DEL(co); } @@ -80,12 +82,15 @@ code_repr(co) int lineno = -1; char *p = GETSTRINGVALUE(co->co_code); char *filename = "???"; + char *name = "???"; if (*p == SET_LINENO) lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8); if (co->co_filename && is_stringobject(co->co_filename)) filename = getstringvalue(co->co_filename); - sprintf(buf, "<code object at %lx, file \"%.400s\", line %d>", - (long)co, filename, lineno); + if (co->co_name && is_stringobject(co->co_name)) + name = getstringvalue(co->co_name); + sprintf(buf, "<code object %.100s at %lx, file \"%.300s\", line %d>", + name, (long)co, filename, lineno); return newstringobject(buf); } @@ -107,18 +112,20 @@ typeobject Codetype = { }; codeobject * -newcodeobject(code, consts, names, filename) +newcodeobject(code, consts, names, filename, name) object *code; object *consts; object *names; object *filename; + object *name; { codeobject *co; int i; /* Check argument types */ if (code == NULL || !is_stringobject(code) || consts == NULL || !is_listobject(consts) || - names == NULL || !is_listobject(names)) { + names == NULL || !is_listobject(names) || + name == NULL || !is_stringobject(name)) { err_badcall(); return NULL; } @@ -140,6 +147,8 @@ newcodeobject(code, consts, names, filename) co->co_names = names; INCREF(filename); co->co_filename = filename; + INCREF(name); + co->co_name = name; } return co; } @@ -162,6 +171,7 @@ struct compiling { int c_block[MAXBLOCKS]; /* stack of block types */ int c_nblocks; /* current block stack level */ char *c_filename; /* filename of current node */ + char *c_name; /* name of object (e.g. function) */ }; @@ -232,6 +242,7 @@ com_init(c, filename) c->c_begin = 0; c->c_nblocks = 0; c->c_filename = filename; + c->c_name = "?"; return 1; fail_0: @@ -2020,6 +2031,8 @@ compile_funcdef(c, n) { node *ch; REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */ + c->c_name = STR(CHILD(n, 1)); + com_addoparg(c, RESERVE_FAST, 0); /* Patched up later */ ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */ ch = CHILD(ch, 1); /* ')' | varargslist */ if (TYPE(ch) == RPAR) @@ -2089,6 +2102,8 @@ compile_node(c, n) /* Optimization for local and global variables. + XXX Need to update this text for LOAD_FAST stuff... + Attempt to replace all LOAD_NAME instructions that refer to a local variable with LOAD_LOCAL instructions, and all that refer to a global variable with LOAD_GLOBAL instructions. @@ -2187,17 +2202,21 @@ compile(n, filename) { struct compiling sc; codeobject *co; - object *v; if (!com_init(&sc, filename)) return NULL; compile_node(&sc, n); com_done(&sc); - if (sc.c_errors == 0 && (v = newstringobject(filename)) != NULL) { - co = newcodeobject(sc.c_code, sc.c_consts, sc.c_names, v); - DECREF(v); + co = NULL; + if (sc.c_errors == 0) { + object *v, *w; + v = newstringobject(sc.c_filename); + w = newstringobject(sc.c_name); + if (v != NULL && w != NULL) + co = newcodeobject(sc.c_code, sc.c_consts, + sc.c_names, v, w); + XDECREF(v); + XDECREF(w); } - else - co = NULL; com_free(&sc); if (co != NULL && filename[0] != '<') optimizer(co); diff --git a/Python/fmod.c b/Python/fmod.c index 607f6a5..8301b94 100644 --- a/Python/fmod.c +++ b/Python/fmod.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/getcwd.c b/Python/getcwd.c index 96c2291..675c4a6 100644 --- a/Python/getcwd.c +++ b/Python/getcwd.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/import.c b/Python/import.c index da9422b..4b7ee13 100644 --- a/Python/import.c +++ b/Python/import.c @@ -52,9 +52,9 @@ extern int verbose; /* Defined in pythonmain.c */ extern char *argv0; #endif -/* Magic word to reject pre-0.9.4 .pyc files */ +/* Magic word to reject pre-0.9.9 .pyc files */ -#define MAGIC 0x949494L +#define MAGIC 0x99BE2AL static object *modules; diff --git a/Python/marshal.c b/Python/marshal.c index 268db00..65f7f2d 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -195,6 +195,7 @@ w_object(v, p) w_object(co->co_consts, p); w_object(co->co_names, p); w_object(co->co_filename, p); + w_object(co->co_name, p); } else { w_byte(TYPE_UNKNOWN, p); @@ -384,9 +385,10 @@ r_object(p) object *consts = r_object(p); object *names = r_object(p); object *filename = r_object(p); + object *name = r_object(p); if (!err_occurred()) { v = (object *) newcodeobject(code, - consts, names, filename); + consts, names, filename, name); } else v = NULL; diff --git a/Python/pythonmain.c b/Python/pythonmain.c index 1c64692..1718611 100644 --- a/Python/pythonmain.c +++ b/Python/pythonmain.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 1bcc083..e59458e 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/strerror.c b/Python/strerror.c index ce9bd98..a2f3acf 100644 --- a/Python/strerror.c +++ b/Python/strerror.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/structmember.c b/Python/structmember.c index e2658a6..6b29c30 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved diff --git a/Python/traceback.c b/Python/traceback.c index 3c246b5..6ed1917 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -1,6 +1,6 @@ /*********************************************************** -Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. All Rights Reserved |