Index: Include/ceval.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/ceval.h,v retrieving revision 2.40 diff -c -r2.40 ceval.h *** Include/ceval.h 2000/09/15 18:19:27 2.40 --- Include/ceval.h 2001/03/21 23:44:35 *************** *** 28,33 **** --- 28,35 ---- DL_IMPORT(PyObject *) PyEval_GetOwner(void); DL_IMPORT(PyObject *) PyEval_GetFrame(void); DL_IMPORT(int) PyEval_GetRestricted(void); + DL_IMPORT(int) PyEval_GetNestedScopes(void); + DL_IMPORT(int) Py_FlushLine(void); Index: Include/compile.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/compile.h,v retrieving revision 2.28 diff -c -r2.28 compile.h *** Include/compile.h 2001/03/01 22:59:14 2.28 --- Include/compile.h 2001/03/21 23:44:35 *************** *** 32,37 **** --- 32,38 ---- #define CO_NEWLOCALS 0x0002 #define CO_VARARGS 0x0004 #define CO_VARKEYWORDS 0x0008 + #define CO_NESTED 0x0010 extern DL_IMPORT(PyTypeObject) PyCode_Type; Index: Include/pythonrun.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/pythonrun.h,v retrieving revision 2.39 diff -c -r2.39 pythonrun.h *** Include/pythonrun.h 2001/03/01 22:59:14 2.39 --- Include/pythonrun.h 2001/03/21 23:44:36 *************** *** 26,37 **** --- 26,41 ---- DL_IMPORT(int) PyRun_AnyFile(FILE *, char *); DL_IMPORT(int) PyRun_AnyFileEx(FILE *, char *, int); + DL_IMPORT(int) PyRun_AnyFileFlags(FILE *, char *, PyCompilerFlags *); + DL_IMPORT(int) PyRun_AnyFileExFlags(FILE *, char *, int, PyCompilerFlags *); + DL_IMPORT(int) PyRun_SimpleString(char *); DL_IMPORT(int) PyRun_SimpleFile(FILE *, char *); DL_IMPORT(int) PyRun_SimpleFileEx(FILE *, char *, int); DL_IMPORT(int) PyRun_InteractiveOne(FILE *, char *); DL_IMPORT(int) PyRun_InteractiveOneFlags(FILE *, char *, PyCompilerFlags *); DL_IMPORT(int) PyRun_InteractiveLoop(FILE *, char *); + DL_IMPORT(int) PyRun_InteractiveLoopFlags(FILE *, char *, PyCompilerFlags *); DL_IMPORT(struct _node *) PyParser_SimpleParseString(char *, int); DL_IMPORT(struct _node *) PyParser_SimpleParseFile(FILE *, char *, int); *************** *** 40,47 **** --- 44,59 ---- DL_IMPORT(PyObject *) PyRun_File(FILE *, char *, int, PyObject *, PyObject *); DL_IMPORT(PyObject *) PyRun_FileEx(FILE *, char *, int, PyObject *, PyObject *, int); + DL_IMPORT(PyObject *) PyRun_StringFlags(char *, int, PyObject *, PyObject *, + PyCompilerFlags *); + DL_IMPORT(PyObject *) PyRun_FileFlags(FILE *, char *, int, PyObject *, + PyObject *, PyCompilerFlags *); + DL_IMPORT(PyObject *) PyRun_FileExFlags(FILE *, char *, int, PyObject *, + PyObject *, int, PyCompilerFlags *); DL_IMPORT(PyObject *) Py_CompileString(char *, char *, int); + DL_IMPORT(PyObject *) Py_CompileStringFlags(char *, char *, int, + PyCompilerFlags *); DL_IMPORT(struct symtable *) Py_SymtableString(char *, char *, int); DL_IMPORT(void) PyErr_Print(void); Index: Modules/main.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/main.c,v retrieving revision 1.50 diff -c -r1.50 main.c *** Modules/main.c 2001/03/02 06:18:03 1.50 --- Modules/main.c 2001/03/21 23:44:38 *************** *** 99,104 **** --- 99,105 ---- int stdin_is_interactive = 0; int help = 0; int version = 0; + PyCompilerFlags cf; orig_argc = argc; /* For Py_GetArgcArgv() */ orig_argv = argv; *************** *** 293,298 **** --- 294,301 ---- Py_DECREF(v); } + cf.cf_nested_scopes = 0; + if (command) { sts = PyRun_SimpleString(command) != 0; free(command); *************** *** 309,323 **** } } } ! sts = PyRun_AnyFileEx( fp, filename == NULL ? "" : filename, ! filename != NULL) != 0; } if (inspect && stdin_is_interactive && (filename != NULL || command != NULL)) ! sts = PyRun_AnyFile(stdin, "") != 0; Py_Finalize(); #ifdef RISCOS --- 312,328 ---- } } } ! /* XXX */ ! sts = PyRun_AnyFileExFlags( fp, filename == NULL ? "" : filename, ! filename != NULL, &cf) != 0; } if (inspect && stdin_is_interactive && (filename != NULL || command != NULL)) ! /* XXX */ ! sts = PyRun_AnyFileFlags(stdin, "", &cf) != 0; Py_Finalize(); #ifdef RISCOS Index: Python/bltinmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v retrieving revision 2.195 diff -c -r2.195 bltinmodule.c *** Python/bltinmodule.c 2001/03/21 18:40:58 2.195 --- Python/bltinmodule.c 2001/03/21 23:44:38 *************** *** 373,379 **** "compile() arg 3 must be 'exec' or 'eval' or 'single'"); return NULL; } ! return Py_CompileString(str, filename, start); } static char compile_doc[] = --- 373,384 ---- "compile() arg 3 must be 'exec' or 'eval' or 'single'"); return NULL; } ! if (PyEval_GetNestedScopes()) { ! PyCompilerFlags cf; ! cf.cf_nested_scopes = 1; ! return Py_CompileStringFlags(str, filename, start, &cf); ! } else ! return Py_CompileString(str, filename, start); } static char compile_doc[] = *************** *** 808,814 **** PyErr_SetFromErrno(PyExc_IOError); return NULL; } ! res = PyRun_FileEx(fp, filename, Py_file_input, globals, locals, 1); return res; } --- 813,826 ---- PyErr_SetFromErrno(PyExc_IOError); return NULL; } ! if (PyEval_GetNestedScopes()) { ! PyCompilerFlags cf; ! cf.cf_nested_scopes = 1; ! res = PyRun_FileExFlags(fp, filename, Py_file_input, globals, ! locals, 1, &cf); ! } else ! res = PyRun_FileEx(fp, filename, Py_file_input, globals, ! locals, 1); return res; } Index: Python/ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.232 diff -c -r2.232 ceval.c *** Python/ceval.c 2001/03/21 16:43:46 2.232 --- Python/ceval.c 2001/03/21 23:44:39 *************** *** 2667,2672 **** --- 2667,2680 ---- } int + PyEval_GetNestedScopes(void) + { + PyFrameObject *current_frame = PyThreadState_Get()->frame; + return current_frame == NULL ? 0 : + current_frame->f_code->co_flags & CO_NESTED; + } + + int Py_FlushLine(void) { PyObject *f = PySys_GetObject("stdout"); *************** *** 3442,3454 **** else if (PyFile_Check(prog)) { FILE *fp = PyFile_AsFile(prog); char *name = PyString_AsString(PyFile_Name(prog)); ! v = PyRun_File(fp, name, Py_file_input, globals, locals); } else { char *str; if (PyString_AsStringAndSize(prog, &str, NULL)) return -1; ! v = PyRun_String(str, Py_file_input, globals, locals); } if (plain) PyFrame_LocalsToFast(f, 0); --- 3450,3476 ---- else if (PyFile_Check(prog)) { FILE *fp = PyFile_AsFile(prog); char *name = PyString_AsString(PyFile_Name(prog)); ! if (PyEval_GetNestedScopes()) { ! PyCompilerFlags cf; ! cf.cf_nested_scopes = 1; ! v = PyRun_FileFlags(fp, name, Py_file_input, globals, ! locals, &cf); ! } else { ! v = PyRun_File(fp, name, Py_file_input, globals, ! locals); ! } } else { char *str; if (PyString_AsStringAndSize(prog, &str, NULL)) return -1; ! if (PyEval_GetNestedScopes()) { ! PyCompilerFlags cf; ! cf.cf_nested_scopes = 1; ! v = PyRun_StringFlags(str, Py_file_input, globals, ! locals, &cf); ! } else ! v = PyRun_String(str, Py_file_input, globals, locals); } if (plain) PyFrame_LocalsToFast(f, 0); Index: Python/compile.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v retrieving revision 2.190 diff -c -r2.190 compile.c *** Python/compile.c 2001/03/21 19:01:33 2.190 --- Python/compile.c 2001/03/21 23:44:39 *************** *** 4276,4281 **** --- 4276,4283 ---- symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste, struct symbol_info *si) { + if (c->c_future && c->c_future->ff_nested_scopes) + c->c_flags |= CO_NESTED; if (ste->ste_type != TYPE_MODULE) c->c_flags |= CO_NEWLOCALS; if (ste->ste_type == TYPE_FUNCTION) { Index: Python/pythonrun.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v retrieving revision 2.126 diff -c -r2.126 pythonrun.c *** Python/pythonrun.c 2001/03/01 22:59:14 2.126 --- Python/pythonrun.c 2001/03/21 23:44:40 *************** *** 40,46 **** PyCompilerFlags *); static PyObject *run_node(node *, char *, PyObject *, PyObject *, PyCompilerFlags *); ! static PyObject *run_pyc_file(FILE *, char *, PyObject *, PyObject *); static void err_input(perrdetail *); static void initsigs(void); static void call_sys_exitfunc(void); --- 40,47 ---- PyCompilerFlags *); static PyObject *run_node(node *, char *, PyObject *, PyObject *, PyCompilerFlags *); ! 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,478 **** int PyRun_AnyFile(FILE *fp, char *filename) { ! return PyRun_AnyFileEx(fp, filename, 0); } int PyRun_AnyFileEx(FILE *fp, char *filename, int closeit) { if (filename == NULL) filename = "???"; if (Py_FdIsInteractive(fp, filename)) { ! int err = PyRun_InteractiveLoop(fp, filename); if (closeit) fclose(fp); return err; } else ! return PyRun_SimpleFileEx(fp, filename, closeit); } int PyRun_InteractiveLoop(FILE *fp, char *filename) { PyObject *v; int ret; ! PyCompilerFlags flags; ! flags.cf_nested_scopes = 0; v = PySys_GetObject("ps1"); if (v == NULL) { PySys_SetObject("ps1", v = PyString_FromString(">>> ")); --- 448,501 ---- int PyRun_AnyFile(FILE *fp, char *filename) { ! 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_InteractiveLoopFlags(fp, filename, flags); if (closeit) fclose(fp); return err; } else ! 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 local_flags; ! 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,490 **** Py_XDECREF(v); } for (;;) { ! ret = PyRun_InteractiveOneFlags(fp, filename, &flags); #ifdef Py_REF_DEBUG fprintf(stderr, "[%ld refs]\n", _Py_RefTotal); #endif --- 507,513 ---- Py_XDECREF(v); } for (;;) { ! ret = PyRun_InteractiveOneFlags(fp, filename, flags); #ifdef Py_REF_DEBUG fprintf(stderr, "[%ld refs]\n", _Py_RefTotal); #endif *************** *** 611,616 **** --- 634,646 ---- 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,638 **** /* 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); } else { ! v = PyRun_FileEx(fp, filename, Py_file_input, d, d, closeit); } if (v == NULL) { PyErr_Print(); --- 660,669 ---- /* 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, flags); } else { ! v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, ! closeit, flags); } if (v == NULL) { PyErr_Print(); *************** *** 926,932 **** PyObject * PyRun_FileEx(FILE *fp, char *filename, int start, PyObject *globals, ! PyObject *locals, int closeit) { node *n = PyParser_SimpleParseFile(fp, filename, start); if (closeit) --- 957,963 ---- PyObject * PyRun_FileEx(FILE *fp, char *filename, int start, PyObject *globals, ! PyObject *locals, int closeit) { node *n = PyParser_SimpleParseFile(fp, filename, start); if (closeit) *************** *** 934,939 **** --- 965,996 ---- 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), + "", 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,955 **** { 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) --- 1006,1011 ---- *************** *** 960,966 **** } static PyObject * ! run_pyc_file(FILE *fp, char *filename, PyObject *globals, PyObject *locals) { PyCodeObject *co; PyObject *v; --- 1016,1023 ---- } static PyObject * ! run_pyc_file(FILE *fp, char *filename, PyObject *globals, PyObject *locals, ! PyCompilerFlags *flags) { PyCodeObject *co; PyObject *v; *************** *** 984,995 **** --- 1041,1065 ---- } 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; } 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;