diff Python/pythonrun.c @ 1263:65a1e4e9cd54 legacy-trunk

* 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.]
author Guido van Rossum <guido@python.org>
date Tue, 30 Mar 1993 17:46:03 +0000
parents f820e6917f07
children e0464e7115ca
line wrap: on
line diff
--- a/Python/pythonrun.c	Tue Mar 30 13:18:41 1993 +0000
+++ b/Python/pythonrun.c	Tue Mar 30 17:46:03 1993 +0000
@@ -263,7 +263,7 @@
 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 @@
 	FILE *fp;
 	char *filename;
 	int start;
-	/*dict*/object *globals, *locals;
+	object *globals, *locals;
 {
 	node *n;
 	int err;
@@ -289,7 +289,7 @@
 	int err;
 	node *n;
 	char *filename;
-	/*dict*/object *globals, *locals;
+	object *globals, *locals;
 {
 	if (err != E_DONE) {
 		err_input(err);
@@ -302,25 +302,9 @@
 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 @@
 	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