summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-07-16 02:29:45 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-07-16 02:29:45 (GMT)
commit5ba58662817b708a453020f0425fe4747ea6d5cb (patch)
tree7d53f1d02fdcc9f6ce4bd1e5130ba1f57269bb3f /Python/ceval.c
parent4dbf87152eb69e8c8c87d3081630c4bc02d7cace (diff)
downloadcpython-5ba58662817b708a453020f0425fe4747ea6d5cb.zip
cpython-5ba58662817b708a453020f0425fe4747ea6d5cb.tar.gz
cpython-5ba58662817b708a453020f0425fe4747ea6d5cb.tar.bz2
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.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index f42165e..e614e17 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2524,7 +2524,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
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 @@ PyEval_GetRestricted(void)
}
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 @@ 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));
- 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)