Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 18611:fdb36a0c7e6e legacy-trunk
Part way to allowing "from __future__ import generators" to communicate
that info to code dynamically compiled *by* code compiled with generators
enabled. Doesn't yet work because there's still no way to tell the parser
that "yield" is OK (unlike nested_scopes, the parser has its fingers in
this too).
Replaced PyEval_GetNestedScopes by a more-general
PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was
*intended* to be part of the public API, so just did.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Mon, 16 Jul 2001 02:29:45 +0000 |
| parents | 65afac84d4f7 |
| children | 09df3254b49d |
line wrap: on
line diff
--- a/Python/ceval.c Mon Jul 16 02:17:14 2001 +0000 +++ b/Python/ceval.c Mon Jul 16 02:29:45 2001 +0000 @@ -2524,7 +2524,7 @@ if (co->co_flags & CO_GENERATOR) { /* Don't need to keep the reference to f_back, it will be set * when the generator is resumed. */ - Py_DECREF(f->f_back); + Py_XDECREF(f->f_back); f->f_back = NULL; /* Create a new generator that owns the ready to run frame @@ -2906,11 +2906,23 @@ } int -PyEval_GetNestedScopes(void) +PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyFrameObject *current_frame = PyThreadState_Get()->frame; - return current_frame == NULL ? 0 : - current_frame->f_code->co_flags & CO_NESTED; + int result = 0; + + if (current_frame != NULL) { + const int codeflags = current_frame->f_code->co_flags; + if (codeflags & CO_NESTED) { + result = 1; + cf->cf_flags |= PyCF_NESTED_SCOPES; + } + if (codeflags & CO_GENERATOR_ALLOWED) { + result = 1; + cf->cf_flags |= PyCF_GENERATORS; + } + } + return result; } int @@ -3730,26 +3742,25 @@ 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; + PyCompilerFlags cf; + cf.cf_flags = 0; + if (PyEval_MergeCompilerFlags(&cf)) v = PyRun_FileFlags(fp, name, Py_file_input, globals, locals, &cf); - } else { + else v = PyRun_File(fp, name, Py_file_input, globals, locals); - } } else { char *str; + PyCompilerFlags cf; if (PyString_AsStringAndSize(prog, &str, NULL)) return -1; - if (PyEval_GetNestedScopes()) { - PyCompilerFlags cf; - cf.cf_nested_scopes = 1; + cf.cf_flags = 0; + if (PyEval_MergeCompilerFlags(&cf)) v = PyRun_StringFlags(str, Py_file_input, globals, locals, &cf); - } else + else v = PyRun_String(str, Py_file_input, globals, locals); } if (plain)
