Extend support for from __future__ import nested_scopes

If a module has a future statement enabling nested scopes, they are
also enable for the exec statement and the functions compile() and
execfile() if they occur in the module.

If Python is run with the -i option, which enters interactive mode
after executing a script, and the script it runs enables nested
scopes, they are also enabled in interactive mode.

XXX The use of -i with -c "from __future__ import nested_scopes" is
not supported.  What's the point?

To support these changes, many function variants have been added to
pythonrun.c.  All the variants names end with Flags and they take an
extra PyCompilerFlags * argument.  It is possible that this complexity
will be eliminated in a future version of the interpreter in which
nested scopes are not optional.
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index f7c2820..edb8a11 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -40,7 +40,8 @@
 			      PyCompilerFlags *);
 static PyObject *run_node(node *, char *, PyObject *, PyObject *,
 			  PyCompilerFlags *);
-static PyObject *run_pyc_file(FILE *, char *, PyObject *, PyObject *);
+static PyObject *run_pyc_file(FILE *, char *, PyObject *, PyObject *,
+			      PyCompilerFlags *);
 static void err_input(perrdetail *);
 static void initsigs(void);
 static void call_sys_exitfunc(void);
@@ -447,32 +448,54 @@
 int
 PyRun_AnyFile(FILE *fp, char *filename)
 {
-	return PyRun_AnyFileEx(fp, filename, 0);
+	return PyRun_AnyFileExFlags(fp, filename, 0, NULL);
+}
+
+int
+PyRun_AnyFileFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
+{
+	return PyRun_AnyFileExFlags(fp, filename, 0, flags);
 }
 
 int
 PyRun_AnyFileEx(FILE *fp, char *filename, int closeit)
 {
+	return PyRun_AnyFileExFlags(fp, filename, closeit, NULL);
+}
+
+int
+PyRun_AnyFileExFlags(FILE *fp, char *filename, int closeit, 
+		     PyCompilerFlags *flags)
+{
 	if (filename == NULL)
 		filename = "???";
 	if (Py_FdIsInteractive(fp, filename)) {
-		int err = PyRun_InteractiveLoop(fp, filename);
+		int err = PyRun_InteractiveLoopFlags(fp, filename, flags);
 		if (closeit)
 			fclose(fp);
 		return err;
 	}
 	else
-		return PyRun_SimpleFileEx(fp, filename, closeit);
+		return PyRun_SimpleFileExFlags(fp, filename, closeit, flags);
 }
 
 int
 PyRun_InteractiveLoop(FILE *fp, char *filename)
 {
+	return PyRun_InteractiveLoopFlags(fp, filename, NULL);
+}
+
+int
+PyRun_InteractiveLoopFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
+{
 	PyObject *v;
 	int ret;
-	PyCompilerFlags flags;
+	PyCompilerFlags local_flags;
 
-	flags.cf_nested_scopes = 0;
+	if (flags == NULL) {
+		flags = &local_flags;
+		local_flags.cf_nested_scopes = 0;
+	}
 	v = PySys_GetObject("ps1");
 	if (v == NULL) {
 		PySys_SetObject("ps1", v = PyString_FromString(">>> "));
@@ -484,7 +507,7 @@
 		Py_XDECREF(v);
 	}
 	for (;;) {
-		ret = PyRun_InteractiveOneFlags(fp, filename, &flags);
+		ret = PyRun_InteractiveOneFlags(fp, filename, flags);
 #ifdef Py_REF_DEBUG
 		fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
 #endif
@@ -611,6 +634,13 @@
 int
 PyRun_SimpleFileEx(FILE *fp, char *filename, int closeit)
 {
+	return PyRun_SimpleFileExFlags(fp, filename, closeit, NULL);
+}
+
+int
+PyRun_SimpleFileExFlags(FILE *fp, char *filename, int closeit,
+			PyCompilerFlags *flags)
+{
 	PyObject *m, *d, *v;
 	char *ext;
 
@@ -630,9 +660,10 @@
 		/* Turn on optimization if a .pyo file is given */
 		if (strcmp(ext, ".pyo") == 0)
 			Py_OptimizeFlag = 1;
-		v = run_pyc_file(fp, filename, d, d);
+		v = run_pyc_file(fp, filename, d, d, flags);
 	} else {
-		v = PyRun_FileEx(fp, filename, Py_file_input, d, d, closeit);
+		v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, 
+				      closeit, flags);
 	}
 	if (v == NULL) {
 		PyErr_Print();
@@ -926,7 +957,7 @@
 
 PyObject *
 PyRun_FileEx(FILE *fp, char *filename, int start, PyObject *globals,
-	   PyObject *locals, int closeit)
+	     PyObject *locals, int closeit)
 {
 	node *n = PyParser_SimpleParseFile(fp, filename, start);
 	if (closeit)
@@ -934,6 +965,32 @@
 	return run_err_node(n, filename, globals, locals, NULL);
 }
 
+PyObject *
+PyRun_StringFlags(char *str, int start, PyObject *globals, PyObject *locals,
+		  PyCompilerFlags *flags)
+{
+	return run_err_node(PyParser_SimpleParseString(str, start),
+			    "<string>", globals, locals, flags);
+}
+
+PyObject *
+PyRun_FileFlags(FILE *fp, char *filename, int start, PyObject *globals,
+		PyObject *locals, PyCompilerFlags *flags)
+{
+	return PyRun_FileExFlags(fp, filename, start, globals, locals, 0,
+				 flags); 
+}
+
+PyObject *
+PyRun_FileExFlags(FILE *fp, char *filename, int start, PyObject *globals,
+		  PyObject *locals, int closeit, PyCompilerFlags *flags)
+{
+	node *n = PyParser_SimpleParseFile(fp, filename, start);
+	if (closeit)
+		fclose(fp);
+	return run_err_node(n, filename, globals, locals, flags);
+}
+
 static PyObject *
 run_err_node(node *n, char *filename, PyObject *globals, PyObject *locals,
 	     PyCompilerFlags *flags)
@@ -949,7 +1006,6 @@
 {
 	PyCodeObject *co;
 	PyObject *v;
-	/* XXX pass sess->ss_nested_scopes to PyNode_Compile */
 	co = PyNode_CompileFlags(n, filename, flags);
 	PyNode_Free(n);
 	if (co == NULL)
@@ -960,7 +1016,8 @@
 }
 
 static PyObject *
-run_pyc_file(FILE *fp, char *filename, PyObject *globals, PyObject *locals)
+run_pyc_file(FILE *fp, char *filename, PyObject *globals, PyObject *locals,
+	     PyCompilerFlags *flags)
 {
 	PyCodeObject *co;
 	PyObject *v;
@@ -984,6 +1041,12 @@
 	}
 	co = (PyCodeObject *)v;
 	v = PyEval_EvalCode(co, globals, locals);
+	if (v && flags) {
+		if (co->co_flags & CO_NESTED)
+			flags->cf_nested_scopes = 1;
+		fprintf(stderr, "run_pyc_file: nested_scopes: %d\n",
+			flags->cf_nested_scopes);			
+	}
 	Py_DECREF(co);
 	return v;
 }
@@ -991,6 +1054,13 @@
 PyObject *
 Py_CompileString(char *str, char *filename, int start)
 {
+	return Py_CompileStringFlags(str, filename, start, NULL);
+}
+
+PyObject *
+Py_CompileStringFlags(char *str, char *filename, int start, 
+		      PyCompilerFlags *flags)
+{
 	node *n;
 	PyCodeObject *co;
 	n = PyParser_SimpleParseString(str, start);