bpo-37253: Add _PyCompilerFlags_INIT macro (GH-14018)

Add a new _PyCompilerFlags_INIT macro to initialize PyCompilerFlags
variables, rather than initializing cf_flags and cf_feature_version
explicitly in each variable.
This commit is contained in:
Victor Stinner 2019-06-13 02:16:41 +02:00 committed by GitHub
parent 2c9b498759
commit 37d66d7d4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 29 deletions

View file

@ -723,12 +723,11 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
const char *str;
int compile_mode = -1;
int is_ast;
PyCompilerFlags cf;
int start[] = {Py_file_input, Py_eval_input, Py_single_input, Py_func_type_input};
PyObject *result;
PyCompilerFlags cf = _PyCompilerFlags_INIT;
cf.cf_flags = flags | PyCF_SOURCE_IS_UTF8;
cf.cf_feature_version = PY_MINOR_VERSION;
if (feature_version >= 0 && (flags & PyCF_ONLY_AST)) {
cf.cf_feature_version = feature_version;
}
@ -889,7 +888,6 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
{
PyObject *result, *source_copy;
const char *str;
PyCompilerFlags cf;
if (locals != Py_None && !PyMapping_Check(locals)) {
PyErr_SetString(PyExc_TypeError, "locals must be a mapping");
@ -941,8 +939,8 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
return PyEval_EvalCode(source, globals, locals);
}
PyCompilerFlags cf = _PyCompilerFlags_INIT;
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
cf.cf_feature_version = PY_MINOR_VERSION;
str = _Py_SourceAsString(source, "eval", "string, bytes or code", &cf, &source_copy);
if (str == NULL)
return NULL;
@ -1032,9 +1030,8 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
else {
PyObject *source_copy;
const char *str;
PyCompilerFlags cf;
PyCompilerFlags cf = _PyCompilerFlags_INIT;
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
cf.cf_feature_version = PY_MINOR_VERSION;
str = _Py_SourceAsString(source, "exec",
"string, bytes or code", &cf,
&source_copy);