Refactor future feature handling
Replace uses of PyCF_xxx with CO_xxx.
Replace individual feature slots in PyFutureFeatures with single
bitmask ff_features.
When flags must be transfered among the three parts of the interpreter
that care about them -- the pythonrun layer, the compiler, and the
future feature parser -- can simply or (|) the definitions.
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 69a7b51..f5fcaf1 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -556,7 +556,7 @@
n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
Py_single_input, ps1, ps2, &err,
(flags &&
- flags->cf_flags & PyCF_GENERATORS) ?
+ flags->cf_flags & CO_GENERATOR_ALLOWED) ?
PyPARSE_YIELD_IS_KEYWORD : 0);
Py_XDECREF(v);
Py_XDECREF(w);
@@ -1009,8 +1009,8 @@
PyCompilerFlags *flags)
{
return run_err_node(PyParser_SimpleParseStringFlags(
- str, start,
- (flags && flags->cf_flags & PyCF_GENERATORS) ?
+ str, start,
+ (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
PyPARSE_YIELD_IS_KEYWORD : 0),
"<string>", globals, locals, flags);
}
@@ -1028,7 +1028,7 @@
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
- (flags && flags->cf_flags & PyCF_GENERATORS) ?
+ (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
PyPARSE_YIELD_IS_KEYWORD : 0);
if (closeit)
fclose(fp);
@@ -1085,18 +1085,8 @@
}
co = (PyCodeObject *)v;
v = PyEval_EvalCode(co, globals, locals);
- if (v && flags) {
- if (co->co_flags & CO_NESTED)
- flags->cf_flags |= PyCF_NESTED_SCOPES;
- if (co->co_flags & CO_GENERATOR_ALLOWED)
- flags->cf_flags |= PyCF_GENERATORS;
-#if 0
- fprintf(stderr, "run_pyc_file: nested_scopes: %d\n",
- flags->cf_flags & PyCF_NESTED_SCOPES);
- fprintf(stderr, "run_pyc_file: generators: %d\n",
- flags->cf_flags & PyCF_GENERATORS);
-#endif
- }
+ if (v && flags)
+ flags->cf_flags |= (co->co_flags & PyCF_MASK);
Py_DECREF(co);
return v;
}
@@ -1114,7 +1104,7 @@
node *n;
PyCodeObject *co;
n = PyParser_SimpleParseStringFlags(str, start,
- (flags && flags->cf_flags & PyCF_GENERATORS) ?
+ (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
PyPARSE_YIELD_IS_KEYWORD : 0);
if (n == NULL)
return NULL;