summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-03-30 17:46:03 (GMT)
committerGuido van Rossum <guido@python.org>1993-03-30 17:46:03 (GMT)
commit5b7221849e240c2a62ebbc48d58607417b42ef44 (patch)
tree28882cac1829c5da2258788ffdb274839f788589 /Python/pythonrun.c
parent8b17d6bd89cd79820c76bd88bc064e44fc03a1bd (diff)
downloadcpython-5b7221849e240c2a62ebbc48d58607417b42ef44.zip
cpython-5b7221849e240c2a62ebbc48d58607417b42ef44.tar.gz
cpython-5b7221849e240c2a62ebbc48d58607417b42ef44.tar.bz2
* 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 <nil> 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.]
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index c387c62..98008b4 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