mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
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:
parent
2c9b498759
commit
37d66d7d4b
8 changed files with 15 additions and 29 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue