From 5b7221849e240c2a62ebbc48d58607417b42ef44 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 30 Mar 1993 17:46:03 +0000 Subject: * Fixed some subtleties with fastlocals. You can no longer access f_fastlocals in a traceback object (this is a core dump hazard if there are entries), but instead eval_code() merges the fast locals back into the locals dictionary if it looks like the local variables will be retained. Also, the merge routines save exceptions since this is sometimes needed (alas!). * Added id() to bltinmodule.c, which returns an object's address (identity). Useful to walk arbitrary data structures containing cycles. * Added compile() to bltinmodule.c and compile_string() to pythonrun.[ch]: support to exec/eval arbitrary code objects. The code that defaults globals and locals is moved from run_node in pythonrun.c (which is now identical to eval_node) to eval_code in ceval.c. [XXX For elegance a clean-up session is necessary.] --- Python/pythonrun.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index c387c62996..98008b4b9b 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -263,7 +263,7 @@ object * run_string(str, start, globals, locals) char *str; int start; - /*dict*/object *globals, *locals; + object *globals, *locals; { node *n; int err; @@ -276,7 +276,7 @@ run_file(fp, filename, start, globals, locals) FILE *fp; char *filename; int start; - /*dict*/object *globals, *locals; + object *globals, *locals; { node *n; int err; @@ -289,7 +289,7 @@ run_err_node(err, n, filename, globals, locals) int err; node *n; char *filename; - /*dict*/object *globals, *locals; + object *globals, *locals; { if (err != E_DONE) { err_input(err); @@ -302,25 +302,9 @@ object * run_node(n, filename, globals, locals) node *n; char *filename; - /*dict*/object *globals, *locals; + object *globals, *locals; { - object *res; - int needmerge = 0; - if (globals == NULL) { - globals = getglobals(); - if (locals == NULL) { - locals = getlocals(); - needmerge = 1; - } - } - else { - if (locals == NULL) - locals = globals; - } - res = eval_node(n, filename, globals, locals); - if (needmerge) - mergelocals(); - return res; + return eval_node(n, filename, globals, locals); } object * @@ -341,6 +325,25 @@ eval_node(n, filename, globals, locals) return v; } +object * +compile_string(str, filename, start) + char *str; + char *filename; + int start; +{ + node *n; + int err; + codeobject *co; + err = parse_string(str, start, &n); + if (err != E_DONE) { + err_input(err); + return NULL; + } + co = compile(n, filename); + freetree(n); + return (object *)co; +} + /* Simplified interface to parsefile */ int -- cgit v1.2.1