From: Jeremy Hylton Date: Thu, 22 Mar 2001 02:32:48 +0000 (+0000) Subject: If a code object is compiled with nested scopes, define the CO_NESTED flag. X-Git-Tag: v2.1b2~93 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=061d106a0f56c5b4171ad8c56ecfaa6cefb27385;p=thirdparty%2FPython%2Fcpython.git If a code object is compiled with nested scopes, define the CO_NESTED flag. Add PyEval_GetNestedScopes() which returns a non-zero value if the code for the current interpreter frame has CO_NESTED defined. --- diff --git a/Include/ceval.h b/Include/ceval.h index 35276260d082..4e6889e20590 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -28,6 +28,7 @@ DL_IMPORT(PyObject *) PyEval_GetLocals(void); 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); diff --git a/Include/compile.h b/Include/compile.h index deb8ee8a980c..e60af59edb63 100644 --- a/Include/compile.h +++ b/Include/compile.h @@ -32,6 +32,7 @@ typedef struct { #define CO_NEWLOCALS 0x0002 #define CO_VARARGS 0x0004 #define CO_VARKEYWORDS 0x0008 +#define CO_NESTED 0x0010 extern DL_IMPORT(PyTypeObject) PyCode_Type; diff --git a/Python/ceval.c b/Python/ceval.c index 156866f0bc2f..658ccb2a0e2c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2666,6 +2666,14 @@ PyEval_GetRestricted(void) return current_frame == NULL ? 0 : current_frame->f_restricted; } +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) { @@ -3448,7 +3456,7 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals, 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); + v = PyRun_File(fp, name, Py_file_input, globals, locals); } else { char *str; diff --git a/Python/compile.c b/Python/compile.c index cd936a3aff6c..81be10351506 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4276,6 +4276,8 @@ static int 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) {