From 495da292255b92dd73758fdd0e4c7d27d82b1e57 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 7 Mar 2019 12:38:08 -0800 Subject: bpo-35975: Support parsing earlier minor versions of Python 3 (GH-12086) This adds a `feature_version` flag to `ast.parse()` (documented) and `compile()` (hidden) that allow tweaking the parser to support older versions of the grammar. In particular if `feature_version` is 5 or 6, the hacks for the `async` and `await` keyword from PEP 492 are reinstated. (For 7 or higher, these are unconditionally treated as keywords, but they are still special tokens rather than `NAME` tokens that the parser driver recognizes.) https://bugs.python.org/issue35975 --- Python/Python-ast.c | 5 + Python/ast.c | 100 ++++++++++++++++---- Python/bltinmodule.c | 11 ++- Python/clinic/bltinmodule.c.h | 15 +-- Python/compile.c | 1 + Python/graminit.c | 210 +++++++++++++++++++++--------------------- Python/pythonrun.c | 6 ++ 7 files changed, 215 insertions(+), 133 deletions(-) (limited to 'Python') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 92ec157571..0411f9f07f 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -8899,6 +8899,11 @@ PyObject* PyAST_mod2obj(mod_ty t) /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) +{ + return PyAST_obj2mod_ex(ast, arena, mode, PY_MINOR_VERSION); +} + +mod_ty PyAST_obj2mod_ex(PyObject* ast, PyArena* arena, int mode, int feature_version) { mod_ty res; PyObject *req_type[3]; diff --git a/Python/ast.c b/Python/ast.c index 2e960485f4..d4ee1b351f 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -564,6 +564,7 @@ struct compiling { PyArena *c_arena; /* Arena for allocating memory. */ PyObject *c_filename; /* filename */ PyObject *c_normalize; /* Normalization function from unicodedata. */ + int c_feature_version; /* Latest minor version of Python for allowed features */ }; static asdl_seq *seq_for_testlist(struct compiling *, const node *); @@ -783,6 +784,7 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags, /* borrowed reference */ c.c_filename = filename; c.c_normalize = NULL; + c.c_feature_version = flags->cf_feature_version; if (TYPE(n) == encoding_decl) n = CHILD(n, 0); @@ -955,7 +957,7 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename_str, */ static operator_ty -get_operator(const node *n) +get_operator(struct compiling *c, const node *n) { switch (TYPE(n)) { case VBAR: @@ -975,6 +977,11 @@ get_operator(const node *n) case STAR: return Mult; case AT: + if (c->c_feature_version < 5) { + ast_error(c, n, + "The '@' operator is only supported in Python 3.5 and greater"); + return (operator_ty)0; + } return MatMult; case SLASH: return Div; @@ -1209,6 +1216,11 @@ ast_for_augassign(struct compiling *c, const node *n) else return Mult; case '@': + if (c->c_feature_version < 5) { + ast_error(c, n, + "The '@' operator is only supported in Python 3.5 and greater"); + return (operator_ty)0; + } return MatMult; default: PyErr_Format(PyExc_SystemError, "invalid augassign: %s", STR(n)); @@ -1518,7 +1530,7 @@ ast_for_arguments(struct compiling *c, const node *n) } else if (found_default) { ast_error(c, n, - "non-default argument follows default argument"); + "non-default argument follows default argument"); return NULL; } arg = ast_for_arg(c, ch); @@ -1719,6 +1731,12 @@ ast_for_funcdef_impl(struct compiling *c, const node *n0, node *tc; string type_comment = NULL; + if (is_async && c->c_feature_version < 5) { + ast_error(c, n, + "Async functions are only supported in Python 3.5 and greater"); + return NULL; + } + REQ(n, funcdef); name = NEW_IDENTIFIER(CHILD(n, name_i)); @@ -1772,10 +1790,9 @@ ast_for_funcdef_impl(struct compiling *c, const node *n0, static stmt_ty ast_for_async_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) { - /* async_funcdef: 'async' funcdef */ + /* async_funcdef: ASYNC funcdef */ REQ(n, async_funcdef); - REQ(CHILD(n, 0), NAME); - assert(strcmp(STR(CHILD(n, 0)), "async") == 0); + REQ(CHILD(n, 0), ASYNC); REQ(CHILD(n, 1), funcdef); return ast_for_funcdef_impl(c, n, decorator_seq, @@ -1794,10 +1811,9 @@ ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) static stmt_ty ast_for_async_stmt(struct compiling *c, const node *n) { - /* async_stmt: 'async' (funcdef | with_stmt | for_stmt) */ + /* async_stmt: ASYNC (funcdef | with_stmt | for_stmt) */ REQ(n, async_stmt); - REQ(CHILD(n, 0), NAME); - assert(strcmp(STR(CHILD(n, 0)), "async") == 0); + REQ(CHILD(n, 0), ASYNC); switch (TYPE(CHILD(n, 1))) { case funcdef: @@ -1948,8 +1964,7 @@ count_comp_fors(struct compiling *c, const node *n) n_fors++; REQ(n, comp_for); if (NCH(n) == 2) { - REQ(CHILD(n, 0), NAME); - assert(strcmp(STR(CHILD(n, 0)), "async") == 0); + REQ(CHILD(n, 0), ASYNC); n = CHILD(n, 1); } else if (NCH(n) == 1) { @@ -2034,8 +2049,7 @@ ast_for_comprehension(struct compiling *c, const node *n) if (NCH(n) == 2) { is_async = 1; - REQ(CHILD(n, 0), NAME); - assert(strcmp(STR(CHILD(n, 0)), "async") == 0); + REQ(CHILD(n, 0), ASYNC); sync_n = CHILD(n, 1); } else { @@ -2043,6 +2057,13 @@ ast_for_comprehension(struct compiling *c, const node *n) } REQ(sync_n, sync_comp_for); + /* Async comprehensions only allowed in Python 3.6 and greater */ + if (is_async && c->c_feature_version < 6) { + ast_error(c, n, + "Async comprehensions are only supported in Python 3.6 and greater"); + return NULL; + } + for_ch = CHILD(sync_n, 1); t = ast_for_exprlist(c, for_ch, Store); if (!t) @@ -2337,7 +2358,15 @@ ast_for_atom(struct compiling *c, const node *n) return str; } case NUMBER: { - PyObject *pynum = parsenumber(c, STR(ch)); + PyObject *pynum; + /* Underscores in numeric literals are only allowed in Python 3.6 or greater */ + /* Check for underscores here rather than in parse_number so we can report a line number on error */ + if (c->c_feature_version < 6 && strchr(STR(ch), '_') != NULL) { + ast_error(c, ch, + "Underscores in numeric literals are only supported in Python 3.6 and greater"); + return NULL; + } + pynum = parsenumber(c, STR(ch)); if (!pynum) return NULL; @@ -2420,8 +2449,8 @@ ast_for_atom(struct compiling *c, const node *n) TYPE(CHILD(ch, 3 - is_dict)) == comp_for) { /* It's a dictionary comprehension. */ if (is_dict) { - ast_error(c, n, "dict unpacking cannot be used in " - "dict comprehension"); + ast_error(c, n, + "dict unpacking cannot be used in dict comprehension"); return NULL; } res = ast_for_dictcomp(c, ch); @@ -2524,7 +2553,7 @@ ast_for_binop(struct compiling *c, const node *n) if (!expr2) return NULL; - newoperator = get_operator(CHILD(n, 1)); + newoperator = get_operator(c, CHILD(n, 1)); if (!newoperator) return NULL; @@ -2539,7 +2568,7 @@ ast_for_binop(struct compiling *c, const node *n) expr_ty tmp_result, tmp; const node* next_oper = CHILD(n, i * 2 + 1); - newoperator = get_operator(next_oper); + newoperator = get_operator(c, next_oper); if (!newoperator) return NULL; @@ -2678,7 +2707,12 @@ ast_for_atom_expr(struct compiling *c, const node *n) REQ(n, atom_expr); nch = NCH(n); - if (TYPE(CHILD(n, 0)) == NAME && strcmp(STR(CHILD(n, 0)), "await") == 0) { + if (TYPE(CHILD(n, 0)) == AWAIT) { + if (c->c_feature_version < 5) { + ast_error(c, n, + "Await expressions are only supported in Python 3.5 and greater"); + return NULL; + } start = 1; assert(nch > 1); } @@ -2775,7 +2809,7 @@ ast_for_expr(struct compiling *c, const node *n) term: factor (('*'|'@'|'/'|'%'|'//') factor)* factor: ('+'|'-'|'~') factor | power power: atom_expr ['**' factor] - atom_expr: ['await'] atom trailer* + atom_expr: [AWAIT] atom trailer* yield_expr: 'yield' [yield_arg] */ @@ -3233,6 +3267,13 @@ ast_for_expr_stmt(struct compiling *c, const node *n) node *deep, *ann = CHILD(n, 1); int simple = 1; + /* AnnAssigns are only allowed in Python 3.6 or greater */ + if (c->c_feature_version < 6) { + ast_error(c, ch, + "Variable annotation syntax is only supported in Python 3.6 and greater"); + return NULL; + } + /* we keep track of parens to qualify (x) as expression not name */ deep = ch; while (NCH(deep) == 1) { @@ -4050,6 +4091,13 @@ ast_for_for_stmt(struct compiling *c, const node *n0, bool is_async) int end_lineno, end_col_offset; int has_type_comment; string type_comment; + + if (is_async && c->c_feature_version < 5) { + ast_error(c, n, + "Async for loops are only supported in Python 3.5 and greater"); + return NULL; + } + /* for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite] */ REQ(n, for_stmt); @@ -4278,6 +4326,12 @@ ast_for_with_stmt(struct compiling *c, const node *n0, bool is_async) asdl_seq *items, *body; string type_comment; + if (is_async && c->c_feature_version < 5) { + ast_error(c, n, + "Async with statements are only supported in Python 3.5 and greater"); + return NULL; + } + REQ(n, with_stmt); has_type_comment = TYPE(CHILD(n, NCH(n) - 2)) == TYPE_COMMENT; @@ -4768,6 +4822,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end, str[len+2] = 0; cf.cf_flags = PyCF_ONLY_AST; + cf.cf_feature_version = PY_MINOR_VERSION; mod_n = PyParser_SimpleParseStringFlagsFilename(str, "", Py_eval_input, 0); if (!mod_n) { @@ -5568,6 +5623,13 @@ parsestr(struct compiling *c, const node *n, int *bytesmode, int *rawmode, } } } + + /* fstrings are only allowed in Python 3.6 and greater */ + if (fmode && c->c_feature_version < 6) { + ast_error(c, n, "Format strings are only supported in Python 3.6 and greater"); + return -1; + } + if (fmode && *bytesmode) { PyErr_BadInternalCall(); return -1; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index a19b8b8ddc..7a2b259cbd 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -745,6 +745,7 @@ compile as builtin_compile flags: int = 0 dont_inherit: bool(accept={int}) = False optimize: int = -1 + feature_version: int = -1 Compile source into a code object that can be executed by exec() or eval(). @@ -763,8 +764,8 @@ in addition to any features explicitly specified. static PyObject * builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, - int optimize) -/*[clinic end generated code: output=1fa176e33452bb63 input=0ff726f595eb9fcd]*/ + int optimize, int feature_version) +/*[clinic end generated code: output=b0c09c84f116d3d7 input=5fcc30651a6acaa9]*/ { PyObject *source_copy; const char *str; @@ -775,6 +776,10 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, PyObject *result; 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; + } if (flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | PyCF_ONLY_AST | PyCF_TYPE_COMMENTS)) @@ -981,6 +986,7 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, } cf.cf_flags = PyCF_SOURCE_IS_UTF8; + cf.cf_feature_version = PY_MINOR_VERSION; str = source_as_string(source, "eval", "string, bytes or code", &cf, &source_copy); if (str == NULL) return NULL; @@ -1068,6 +1074,7 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, const char *str; PyCompilerFlags cf; cf.cf_flags = PyCF_SOURCE_IS_UTF8; + cf.cf_feature_version = PY_MINOR_VERSION; str = source_as_string(source, "exec", "string, bytes or code", &cf, &source_copy); diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 1b82f773ed..df9970942b 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -151,7 +151,7 @@ exit: PyDoc_STRVAR(builtin_compile__doc__, "compile($module, /, source, filename, mode, flags=0,\n" -" dont_inherit=False, optimize=-1)\n" +" dont_inherit=False, optimize=-1, feature_version=-1)\n" "--\n" "\n" "Compile source into a code object that can be executed by exec() or eval().\n" @@ -173,26 +173,27 @@ PyDoc_STRVAR(builtin_compile__doc__, static PyObject * builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, - int optimize); + int optimize, int feature_version); static PyObject * builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; - static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL}; - static _PyArg_Parser _parser = {"OO&s|iii:compile", _keywords, 0}; + static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "feature_version", NULL}; + static _PyArg_Parser _parser = {"OO&s|iiii:compile", _keywords, 0}; PyObject *source; PyObject *filename; const char *mode; int flags = 0; int dont_inherit = 0; int optimize = -1; + int feature_version = -1; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) { + &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize, &feature_version)) { goto exit; } - return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize); + return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version); exit: return return_value; @@ -754,4 +755,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=54e5e33dcc2659e0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=00b97a48ea49eaf2 input=a9049054013a1b77]*/ diff --git a/Python/compile.c b/Python/compile.c index c26210675d..697833752b 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -330,6 +330,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags, goto finally; if (!flags) { local_flags.cf_flags = 0; + local_flags.cf_feature_version = PY_MINOR_VERSION; flags = &local_flags; } merged = c.c_future->ff_features | flags->cf_flags; diff --git a/Python/graminit.c b/Python/graminit.c index 6cb7bbc9f7..24f6f6c72a 100644 --- a/Python/graminit.c +++ b/Python/graminit.c @@ -106,7 +106,7 @@ static state states_5[3] = { {1, arcs_5_2}, }; static arc arcs_6_0[1] = { - {16, 1}, + {38, 1}, }; static arc arcs_6_1[1] = { {56, 2}, @@ -120,7 +120,7 @@ static state states_6[3] = { {1, arcs_6_2}, }; static arc arcs_7_0[1] = { - {21, 1}, + {19, 1}, }; static arc arcs_7_1[1] = { {40, 2}, @@ -583,7 +583,7 @@ static state states_19[2] = { {1, arcs_19_1}, }; static arc arcs_20_0[1] = { - {22, 1}, + {20, 1}, }; static arc arcs_20_1[1] = { {98, 2}, @@ -597,7 +597,7 @@ static state states_20[3] = { {1, arcs_20_2}, }; static arc arcs_21_0[1] = { - {31, 1}, + {29, 1}, }; static arc arcs_21_1[1] = { {0, 1}, @@ -621,7 +621,7 @@ static state states_22[2] = { {1, arcs_22_1}, }; static arc arcs_23_0[1] = { - {18, 1}, + {16, 1}, }; static arc arcs_23_1[1] = { {0, 1}, @@ -631,7 +631,7 @@ static state states_23[2] = { {1, arcs_23_1}, }; static arc arcs_24_0[1] = { - {20, 1}, + {18, 1}, }; static arc arcs_24_1[1] = { {0, 1}, @@ -641,7 +641,7 @@ static state states_24[2] = { {1, arcs_24_1}, }; static arc arcs_25_0[1] = { - {33, 1}, + {31, 1}, }; static arc arcs_25_1[2] = { {80, 2}, @@ -666,14 +666,14 @@ static state states_26[2] = { {1, arcs_26_1}, }; static arc arcs_27_0[1] = { - {32, 1}, + {30, 1}, }; static arc arcs_27_1[2] = { {60, 2}, {0, 1}, }; static arc arcs_27_2[2] = { - {24, 3}, + {22, 3}, {0, 2}, }; static arc arcs_27_3[1] = { @@ -701,7 +701,7 @@ static state states_28[2] = { {1, arcs_28_1}, }; static arc arcs_29_0[1] = { - {27, 1}, + {25, 1}, }; static arc arcs_29_1[1] = { {106, 2}, @@ -715,7 +715,7 @@ static state states_29[3] = { {1, arcs_29_2}, }; static arc arcs_30_0[1] = { - {24, 1}, + {22, 1}, }; static arc arcs_30_1[3] = { {107, 2}, @@ -725,11 +725,11 @@ static arc arcs_30_1[3] = { static arc arcs_30_2[4] = { {107, 2}, {9, 2}, - {27, 4}, + {25, 4}, {49, 3}, }; static arc arcs_30_3[1] = { - {27, 4}, + {25, 4}, }; static arc arcs_30_4[3] = { {5, 5}, @@ -832,7 +832,7 @@ static state states_35[2] = { {2, arcs_35_1}, }; static arc arcs_36_0[1] = { - {25, 1}, + {23, 1}, }; static arc arcs_36_1[1] = { {40, 2}, @@ -847,7 +847,7 @@ static state states_36[3] = { {2, arcs_36_2}, }; static arc arcs_37_0[1] = { - {29, 1}, + {27, 1}, }; static arc arcs_37_1[1] = { {40, 2}, @@ -903,7 +903,7 @@ static state states_39[2] = { {1, arcs_39_1}, }; static arc arcs_40_0[1] = { - {16, 1}, + {38, 1}, }; static arc arcs_40_1[3] = { {113, 2}, @@ -919,7 +919,7 @@ static state states_40[3] = { {1, arcs_40_2}, }; static arc arcs_41_0[1] = { - {26, 1}, + {24, 1}, }; static arc arcs_41_1[1] = { {118, 2}, @@ -955,7 +955,7 @@ static state states_41[8] = { {1, arcs_41_7}, }; static arc arcs_42_0[1] = { - {35, 1}, + {33, 1}, }; static arc arcs_42_1[1] = { {118, 2}, @@ -990,7 +990,7 @@ static state states_42[8] = { {1, arcs_42_7}, }; static arc arcs_43_0[1] = { - {23, 1}, + {21, 1}, }; static arc arcs_43_1[1] = { {98, 2}, @@ -1038,7 +1038,7 @@ static state states_43[11] = { {1, arcs_43_10}, }; static arc arcs_44_0[1] = { - {34, 1}, + {32, 1}, }; static arc arcs_44_1[1] = { {59, 2}, @@ -1097,7 +1097,7 @@ static state states_44[13] = { {2, arcs_44_12}, }; static arc arcs_45_0[1] = { - {36, 1}, + {34, 1}, }; static arc arcs_45_1[1] = { {125, 2}, @@ -1218,7 +1218,7 @@ static arc arcs_50_1[1] = { {0, 1}, }; static arc arcs_50_2[2] = { - {26, 3}, + {24, 3}, {0, 2}, }; static arc arcs_50_3[1] = { @@ -1250,7 +1250,7 @@ static state states_51[2] = { {1, arcs_51_1}, }; static arc arcs_52_0[1] = { - {28, 1}, + {26, 1}, }; static arc arcs_52_1[2] = { {59, 2}, @@ -1273,7 +1273,7 @@ static state states_52[5] = { {1, arcs_52_4}, }; static arc arcs_53_0[1] = { - {28, 1}, + {26, 1}, }; static arc arcs_53_1[2] = { {59, 2}, @@ -1318,7 +1318,7 @@ static state states_55[2] = { {2, arcs_55_1}, }; static arc arcs_56_0[2] = { - {30, 1}, + {28, 1}, {139, 2}, }; static arc arcs_56_1[1] = { @@ -1353,13 +1353,13 @@ static arc arcs_58_0[10] = { {146, 1}, {122, 1}, {147, 2}, - {30, 3}, + {28, 3}, }; static arc arcs_58_1[1] = { {0, 1}, }; static arc arcs_58_2[2] = { - {30, 1}, + {28, 1}, {0, 2}, }; static arc arcs_58_3[1] = { @@ -1460,7 +1460,7 @@ static state states_65[2] = { static arc arcs_66_0[4] = { {7, 1}, {8, 1}, - {39, 1}, + {37, 1}, {162, 2}, }; static arc arcs_66_1[1] = { @@ -1494,7 +1494,7 @@ static state states_67[4] = { {1, arcs_67_3}, }; static arc arcs_68_0[2] = { - {17, 1}, + {39, 1}, {164, 2}, }; static arc arcs_68_1[1] = { @@ -1516,7 +1516,7 @@ static arc arcs_69_0[10] = { {12, 2}, {13, 2}, {14, 3}, - {38, 4}, + {36, 4}, {40, 2}, {41, 2}, {42, 5}, @@ -1788,7 +1788,7 @@ static state states_77[14] = { {1, arcs_77_13}, }; static arc arcs_78_0[1] = { - {19, 1}, + {17, 1}, }; static arc arcs_78_1[1] = { {40, 2}, @@ -1874,7 +1874,7 @@ static state states_81[2] = { {1, arcs_81_1}, }; static arc arcs_82_0[1] = { - {23, 1}, + {21, 1}, }; static arc arcs_82_1[1] = { {98, 2}, @@ -1901,7 +1901,7 @@ static state states_82[6] = { {1, arcs_82_5}, }; static arc arcs_83_0[2] = { - {16, 1}, + {38, 1}, {177, 2}, }; static arc arcs_83_1[1] = { @@ -1916,7 +1916,7 @@ static state states_83[3] = { {1, arcs_83_2}, }; static arc arcs_84_0[1] = { - {26, 1}, + {24, 1}, }; static arc arcs_84_1[1] = { {133, 2}, @@ -1945,7 +1945,7 @@ static state states_85[2] = { {1, arcs_85_1}, }; static arc arcs_86_0[1] = { - {37, 1}, + {35, 1}, }; static arc arcs_86_1[2] = { {179, 2}, @@ -1960,7 +1960,7 @@ static state states_86[3] = { {1, arcs_86_2}, }; static arc arcs_87_0[2] = { - {24, 1}, + {22, 1}, {80, 2}, }; static arc arcs_87_1[1] = { @@ -2115,7 +2115,7 @@ static dfa dfas[92] = { {257, "file_input", 0, 2, states_1, "\344\377\377\377\377\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {258, "eval_input", 0, 3, states_2, - "\240\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {259, "decorator", 0, 7, states_3, "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {260, "decorators", 0, 2, states_4, @@ -2123,9 +2123,9 @@ static dfa dfas[92] = { {261, "decorated", 0, 3, states_5, "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {262, "async_funcdef", 0, 3, states_6, - "\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {263, "funcdef", 0, 9, states_7, - "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {264, "parameters", 0, 4, states_8, "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {265, "typedargslist", 0, 22, states_9, @@ -2139,39 +2139,39 @@ static dfa dfas[92] = { {269, "stmt", 0, 2, states_13, "\340\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {270, "simple_stmt", 0, 4, states_14, - "\340\373\126\373\343\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {271, "small_stmt", 0, 2, states_15, - "\340\373\126\373\343\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {272, "expr_stmt", 0, 6, states_16, - "\340\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {273, "annassign", 0, 5, states_17, "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {274, "testlist_star_expr", 0, 3, states_18, - "\340\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {275, "augassign", 0, 2, states_19, "\000\000\000\000\000\000\000\000\000\000\340\377\003\000\000\000\000\000\000\000\000\000\000"}, {276, "del_stmt", 0, 3, states_20, - "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {277, "pass_stmt", 0, 2, states_21, - "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {278, "flow_stmt", 0, 2, states_22, - "\000\000\024\000\043\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\005\300\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {279, "break_stmt", 0, 2, states_23, - "\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {280, "continue_stmt", 0, 2, states_24, - "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {281, "return_stmt", 0, 3, states_25, - "\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {282, "yield_stmt", 0, 2, states_26, - "\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {283, "raise_stmt", 0, 5, states_27, - "\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {284, "import_stmt", 0, 2, states_28, - "\000\000\000\011\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\100\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {285, "import_name", 0, 3, states_29, - "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {286, "import_from", 0, 8, states_30, - "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {287, "import_as_name", 0, 4, states_31, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {288, "dotted_as_name", 0, 4, states_32, @@ -2183,117 +2183,117 @@ static dfa dfas[92] = { {291, "dotted_name", 0, 2, states_35, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {292, "global_stmt", 0, 3, states_36, - "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {293, "nonlocal_stmt", 0, 3, states_37, - "\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {294, "assert_stmt", 0, 5, states_38, "\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {295, "compound_stmt", 0, 2, states_39, - "\000\004\251\004\034\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\004\052\001\107\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {296, "async_stmt", 0, 3, states_40, - "\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {297, "if_stmt", 0, 8, states_41, - "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {298, "while_stmt", 0, 8, states_42, - "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {299, "for_stmt", 0, 11, states_43, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {300, "try_stmt", 0, 13, states_44, - "\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {301, "with_stmt", 0, 6, states_45, - "\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {302, "with_item", 0, 4, states_46, - "\240\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {303, "except_clause", 0, 5, states_47, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"}, {304, "suite", 0, 5, states_48, - "\344\373\126\373\343\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {305, "namedexpr_test", 0, 4, states_49, - "\240\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {306, "test", 0, 6, states_50, - "\240\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {307, "test_nocond", 0, 2, states_51, - "\240\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {308, "lambdef", 0, 5, states_52, - "\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {309, "lambdef_nocond", 0, 5, states_53, - "\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {310, "or_test", 0, 2, states_54, - "\240\173\002\100\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {311, "and_test", 0, 2, states_55, - "\240\173\002\100\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {312, "not_test", 0, 3, states_56, - "\240\173\002\100\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {313, "comparison", 0, 2, states_57, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {314, "comp_op", 0, 4, states_58, - "\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\004\000\340\017\000\000\000\000"}, + "\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\004\000\340\017\000\000\000\000"}, {315, "star_expr", 0, 3, states_59, "\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {316, "expr", 0, 2, states_60, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {317, "xor_expr", 0, 2, states_61, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {318, "and_expr", 0, 2, states_62, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {319, "shift_expr", 0, 2, states_63, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {320, "arith_expr", 0, 2, states_64, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {321, "term", 0, 2, states_65, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {322, "factor", 0, 3, states_66, - "\240\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {323, "power", 0, 4, states_67, - "\040\172\002\000\100\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {324, "atom_expr", 0, 3, states_68, - "\040\172\002\000\100\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {325, "atom", 0, 9, states_69, - "\040\172\000\000\100\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\040\172\000\000\020\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {326, "testlist_comp", 0, 5, states_70, - "\340\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {327, "trailer", 0, 7, states_71, "\040\100\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, {328, "subscriptlist", 0, 3, states_72, - "\240\173\002\120\300\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {329, "subscript", 0, 5, states_73, - "\240\173\002\120\300\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {330, "sliceop", 0, 3, states_74, "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {331, "exprlist", 0, 3, states_75, - "\340\173\002\000\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {332, "testlist", 0, 3, states_76, - "\240\173\002\120\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {333, "dictorsetmaker", 0, 14, states_77, - "\340\173\002\120\300\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {334, "classdef", 0, 8, states_78, - "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {335, "arglist", 0, 3, states_79, - "\340\173\002\120\300\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {336, "argument", 0, 4, states_80, - "\340\173\002\120\300\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {337, "comp_iter", 0, 2, states_81, - "\000\000\201\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\040\001\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {338, "sync_comp_for", 0, 6, states_82, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {339, "comp_for", 0, 3, states_83, - "\000\000\201\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\040\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {340, "comp_if", 0, 4, states_84, - "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {341, "encoding_decl", 0, 2, states_85, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {342, "yield_expr", 0, 3, states_86, - "\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {343, "yield_arg", 0, 3, states_87, - "\340\173\002\121\300\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\100\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {344, "func_body_suite", 0, 7, states_88, - "\344\373\126\373\343\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {345, "func_type_input", 0, 3, states_89, "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {346, "func_type", 0, 6, states_90, "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {347, "typelist", 0, 11, states_91, - "\340\173\002\120\300\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, }; static label labels[183] = { {0, "EMPTY"}, @@ -2312,8 +2312,6 @@ static label labels[183] = { {1, "True"}, {9, 0}, {1, "assert"}, - {1, "async"}, - {1, "await"}, {1, "break"}, {1, "class"}, {1, "continue"}, @@ -2336,6 +2334,8 @@ static label labels[183] = { {1, "yield"}, {25, 0}, {31, 0}, + {56, 0}, + {55, 0}, {1, 0}, {2, 0}, {3, 0}, @@ -2357,7 +2357,7 @@ static label labels[183] = { {51, 0}, {11, 0}, {306, 0}, - {56, 0}, + {58, 0}, {344, 0}, {265, 0}, {35, 0}, diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 906877a0a8..199ea82434 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -105,6 +105,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags * if (flags == NULL) { flags = &local_flags; local_flags.cf_flags = 0; + local_flags.cf_feature_version = PY_MINOR_VERSION; } v = _PySys_GetObjectId(&PyId_ps1); if (v == NULL) { @@ -1165,6 +1166,7 @@ Py_SymtableStringObject(const char *str, PyObject *filename, int start) return NULL; flags.cf_flags = 0; + flags.cf_feature_version = PY_MINOR_VERSION; mod = PyParser_ASTFromStringObject(str, filename, start, &flags, arena); if (mod == NULL) { PyArena_Free(arena); @@ -1198,12 +1200,15 @@ PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start, PyCompilerFlags localflags; perrdetail err; int iflags = PARSER_FLAGS(flags); + if (flags && flags->cf_feature_version < 7) + iflags |= PyPARSE_ASYNC_HACKS; node *n = PyParser_ParseStringObject(s, filename, &_PyParser_Grammar, start, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; + localflags.cf_feature_version = PY_MINOR_VERSION; flags = &localflags; } if (n) { @@ -1249,6 +1254,7 @@ PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc, start, ps1, ps2, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; + localflags.cf_feature_version = PY_MINOR_VERSION; flags = &localflags; } if (n) { -- cgit v1.2.1 From ab9b31f94737895f0121f26ba3ad718ebbc24fe1 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 8 Mar 2019 10:58:00 -0800 Subject: bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690) --- Python/importlib_external.h | 1747 ++++++++++++++++++++++--------------------- 1 file changed, 878 insertions(+), 869 deletions(-) (limited to 'Python') diff --git a/Python/importlib_external.h b/Python/importlib_external.h index ca83eb575c..ea4d895349 100644 --- a/Python/importlib_external.h +++ b/Python/importlib_external.h @@ -1771,883 +1771,892 @@ const unsigned char _Py_M__importlib_bootstrap_external[] = { 0,115,22,0,0,0,8,2,4,6,8,4,8,4,8,3, 8,8,8,6,8,6,8,4,8,4,2,1,114,15,1,0, 0,99,0,0,0,0,0,0,0,0,0,0,0,0,2,0, - 0,0,64,0,0,0,115,96,0,0,0,101,0,90,1,100, + 0,0,64,0,0,0,115,104,0,0,0,101,0,90,1,100, 0,90,2,100,1,90,3,100,2,100,3,132,0,90,4,100, 4,100,5,132,0,90,5,100,6,100,7,132,0,90,6,100, 8,100,9,132,0,90,7,100,10,100,11,132,0,90,8,100, 12,100,13,132,0,90,9,100,14,100,15,132,0,90,10,100, 16,100,17,132,0,90,11,100,18,100,19,132,0,90,12,100, - 20,100,21,132,0,90,13,100,22,83,0,41,23,218,14,95, - 78,97,109,101,115,112,97,99,101,80,97,116,104,97,38,1, - 0,0,82,101,112,114,101,115,101,110,116,115,32,97,32,110, - 97,109,101,115,112,97,99,101,32,112,97,99,107,97,103,101, - 39,115,32,112,97,116,104,46,32,32,73,116,32,117,115,101, - 115,32,116,104,101,32,109,111,100,117,108,101,32,110,97,109, - 101,10,32,32,32,32,116,111,32,102,105,110,100,32,105,116, - 115,32,112,97,114,101,110,116,32,109,111,100,117,108,101,44, - 32,97,110,100,32,102,114,111,109,32,116,104,101,114,101,32, - 105,116,32,108,111,111,107,115,32,117,112,32,116,104,101,32, - 112,97,114,101,110,116,39,115,10,32,32,32,32,95,95,112, - 97,116,104,95,95,46,32,32,87,104,101,110,32,116,104,105, - 115,32,99,104,97,110,103,101,115,44,32,116,104,101,32,109, - 111,100,117,108,101,39,115,32,111,119,110,32,112,97,116,104, - 32,105,115,32,114,101,99,111,109,112,117,116,101,100,44,10, - 32,32,32,32,117,115,105,110,103,32,112,97,116,104,95,102, - 105,110,100,101,114,46,32,32,70,111,114,32,116,111,112,45, - 108,101,118,101,108,32,109,111,100,117,108,101,115,44,32,116, - 104,101,32,112,97,114,101,110,116,32,109,111,100,117,108,101, - 39,115,32,112,97,116,104,10,32,32,32,32,105,115,32,115, - 121,115,46,112,97,116,104,46,99,4,0,0,0,0,0,0, - 0,4,0,0,0,3,0,0,0,67,0,0,0,115,36,0, - 0,0,124,1,124,0,95,0,124,2,124,0,95,1,116,2, - 124,0,160,3,161,0,131,1,124,0,95,4,124,3,124,0, - 95,5,100,0,83,0,114,110,0,0,0,41,6,218,5,95, - 110,97,109,101,218,5,95,112,97,116,104,114,112,0,0,0, - 218,16,95,103,101,116,95,112,97,114,101,110,116,95,112,97, - 116,104,218,17,95,108,97,115,116,95,112,97,114,101,110,116, - 95,112,97,116,104,218,12,95,112,97,116,104,95,102,105,110, - 100,101,114,169,4,114,119,0,0,0,114,117,0,0,0,114, - 44,0,0,0,90,11,112,97,116,104,95,102,105,110,100,101, - 114,114,3,0,0,0,114,3,0,0,0,114,6,0,0,0, - 114,209,0,0,0,106,4,0,0,115,8,0,0,0,0,1, - 6,1,6,1,14,1,122,23,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,46,95,95,105,110,105,116,95,95,99, - 1,0,0,0,0,0,0,0,4,0,0,0,3,0,0,0, - 67,0,0,0,115,38,0,0,0,124,0,106,0,160,1,100, - 1,161,1,92,3,125,1,125,2,125,3,124,2,100,2,107, - 2,114,30,100,3,83,0,124,1,100,4,102,2,83,0,41, - 5,122,62,82,101,116,117,114,110,115,32,97,32,116,117,112, - 108,101,32,111,102,32,40,112,97,114,101,110,116,45,109,111, - 100,117,108,101,45,110,97,109,101,44,32,112,97,114,101,110, - 116,45,112,97,116,104,45,97,116,116,114,45,110,97,109,101, - 41,114,71,0,0,0,114,40,0,0,0,41,2,114,8,0, - 0,0,114,44,0,0,0,90,8,95,95,112,97,116,104,95, - 95,41,2,114,23,1,0,0,114,41,0,0,0,41,4,114, - 119,0,0,0,114,13,1,0,0,218,3,100,111,116,90,2, - 109,101,114,3,0,0,0,114,3,0,0,0,114,6,0,0, - 0,218,23,95,102,105,110,100,95,112,97,114,101,110,116,95, - 112,97,116,104,95,110,97,109,101,115,112,4,0,0,115,8, - 0,0,0,0,2,18,1,8,2,4,3,122,38,95,78,97, - 109,101,115,112,97,99,101,80,97,116,104,46,95,102,105,110, - 100,95,112,97,114,101,110,116,95,112,97,116,104,95,110,97, - 109,101,115,99,1,0,0,0,0,0,0,0,3,0,0,0, - 3,0,0,0,67,0,0,0,115,28,0,0,0,124,0,160, - 0,161,0,92,2,125,1,125,2,116,1,116,2,106,3,124, - 1,25,0,124,2,131,2,83,0,114,110,0,0,0,41,4, - 114,30,1,0,0,114,130,0,0,0,114,8,0,0,0,218, - 7,109,111,100,117,108,101,115,41,3,114,119,0,0,0,90, - 18,112,97,114,101,110,116,95,109,111,100,117,108,101,95,110, - 97,109,101,90,14,112,97,116,104,95,97,116,116,114,95,110, - 97,109,101,114,3,0,0,0,114,3,0,0,0,114,6,0, - 0,0,114,25,1,0,0,122,4,0,0,115,4,0,0,0, - 0,1,12,1,122,31,95,78,97,109,101,115,112,97,99,101, - 80,97,116,104,46,95,103,101,116,95,112,97,114,101,110,116, - 95,112,97,116,104,99,1,0,0,0,0,0,0,0,3,0, - 0,0,4,0,0,0,67,0,0,0,115,80,0,0,0,116, - 0,124,0,160,1,161,0,131,1,125,1,124,1,124,0,106, - 2,107,3,114,74,124,0,160,3,124,0,106,4,124,1,161, - 2,125,2,124,2,100,0,107,9,114,68,124,2,106,5,100, - 0,107,8,114,68,124,2,106,6,114,68,124,2,106,6,124, - 0,95,7,124,1,124,0,95,2,124,0,106,7,83,0,114, - 110,0,0,0,41,8,114,112,0,0,0,114,25,1,0,0, - 114,26,1,0,0,114,27,1,0,0,114,23,1,0,0,114, - 140,0,0,0,114,178,0,0,0,114,24,1,0,0,41,3, - 114,119,0,0,0,90,11,112,97,114,101,110,116,95,112,97, - 116,104,114,187,0,0,0,114,3,0,0,0,114,3,0,0, - 0,114,6,0,0,0,218,12,95,114,101,99,97,108,99,117, - 108,97,116,101,126,4,0,0,115,16,0,0,0,0,2,12, - 1,10,1,14,3,18,1,6,1,8,1,6,1,122,27,95, - 78,97,109,101,115,112,97,99,101,80,97,116,104,46,95,114, - 101,99,97,108,99,117,108,97,116,101,99,1,0,0,0,0, - 0,0,0,1,0,0,0,3,0,0,0,67,0,0,0,115, - 12,0,0,0,116,0,124,0,160,1,161,0,131,1,83,0, - 114,110,0,0,0,41,2,114,5,1,0,0,114,32,1,0, - 0,114,246,0,0,0,114,3,0,0,0,114,3,0,0,0, - 114,6,0,0,0,218,8,95,95,105,116,101,114,95,95,139, - 4,0,0,115,2,0,0,0,0,1,122,23,95,78,97,109, - 101,115,112,97,99,101,80,97,116,104,46,95,95,105,116,101, - 114,95,95,99,3,0,0,0,0,0,0,0,3,0,0,0, - 3,0,0,0,67,0,0,0,115,14,0,0,0,124,2,124, - 0,106,0,124,1,60,0,100,0,83,0,114,110,0,0,0, - 41,1,114,24,1,0,0,41,3,114,119,0,0,0,218,5, - 105,110,100,101,120,114,44,0,0,0,114,3,0,0,0,114, - 3,0,0,0,114,6,0,0,0,218,11,95,95,115,101,116, - 105,116,101,109,95,95,142,4,0,0,115,2,0,0,0,0, - 1,122,26,95,78,97,109,101,115,112,97,99,101,80,97,116, - 104,46,95,95,115,101,116,105,116,101,109,95,95,99,1,0, + 20,100,21,132,0,90,13,100,22,100,23,132,0,90,14,100, + 24,83,0,41,25,218,14,95,78,97,109,101,115,112,97,99, + 101,80,97,116,104,97,38,1,0,0,82,101,112,114,101,115, + 101,110,116,115,32,97,32,110,97,109,101,115,112,97,99,101, + 32,112,97,99,107,97,103,101,39,115,32,112,97,116,104,46, + 32,32,73,116,32,117,115,101,115,32,116,104,101,32,109,111, + 100,117,108,101,32,110,97,109,101,10,32,32,32,32,116,111, + 32,102,105,110,100,32,105,116,115,32,112,97,114,101,110,116, + 32,109,111,100,117,108,101,44,32,97,110,100,32,102,114,111, + 109,32,116,104,101,114,101,32,105,116,32,108,111,111,107,115, + 32,117,112,32,116,104,101,32,112,97,114,101,110,116,39,115, + 10,32,32,32,32,95,95,112,97,116,104,95,95,46,32,32, + 87,104,101,110,32,116,104,105,115,32,99,104,97,110,103,101, + 115,44,32,116,104,101,32,109,111,100,117,108,101,39,115,32, + 111,119,110,32,112,97,116,104,32,105,115,32,114,101,99,111, + 109,112,117,116,101,100,44,10,32,32,32,32,117,115,105,110, + 103,32,112,97,116,104,95,102,105,110,100,101,114,46,32,32, + 70,111,114,32,116,111,112,45,108,101,118,101,108,32,109,111, + 100,117,108,101,115,44,32,116,104,101,32,112,97,114,101,110, + 116,32,109,111,100,117,108,101,39,115,32,112,97,116,104,10, + 32,32,32,32,105,115,32,115,121,115,46,112,97,116,104,46, + 99,4,0,0,0,0,0,0,0,4,0,0,0,3,0,0, + 0,67,0,0,0,115,36,0,0,0,124,1,124,0,95,0, + 124,2,124,0,95,1,116,2,124,0,160,3,161,0,131,1, + 124,0,95,4,124,3,124,0,95,5,100,0,83,0,114,110, + 0,0,0,41,6,218,5,95,110,97,109,101,218,5,95,112, + 97,116,104,114,112,0,0,0,218,16,95,103,101,116,95,112, + 97,114,101,110,116,95,112,97,116,104,218,17,95,108,97,115, + 116,95,112,97,114,101,110,116,95,112,97,116,104,218,12,95, + 112,97,116,104,95,102,105,110,100,101,114,169,4,114,119,0, + 0,0,114,117,0,0,0,114,44,0,0,0,90,11,112,97, + 116,104,95,102,105,110,100,101,114,114,3,0,0,0,114,3, + 0,0,0,114,6,0,0,0,114,209,0,0,0,106,4,0, + 0,115,8,0,0,0,0,1,6,1,6,1,14,1,122,23, + 95,78,97,109,101,115,112,97,99,101,80,97,116,104,46,95, + 95,105,110,105,116,95,95,99,1,0,0,0,0,0,0,0, + 4,0,0,0,3,0,0,0,67,0,0,0,115,38,0,0, + 0,124,0,106,0,160,1,100,1,161,1,92,3,125,1,125, + 2,125,3,124,2,100,2,107,2,114,30,100,3,83,0,124, + 1,100,4,102,2,83,0,41,5,122,62,82,101,116,117,114, + 110,115,32,97,32,116,117,112,108,101,32,111,102,32,40,112, + 97,114,101,110,116,45,109,111,100,117,108,101,45,110,97,109, + 101,44,32,112,97,114,101,110,116,45,112,97,116,104,45,97, + 116,116,114,45,110,97,109,101,41,114,71,0,0,0,114,40, + 0,0,0,41,2,114,8,0,0,0,114,44,0,0,0,90, + 8,95,95,112,97,116,104,95,95,41,2,114,23,1,0,0, + 114,41,0,0,0,41,4,114,119,0,0,0,114,13,1,0, + 0,218,3,100,111,116,90,2,109,101,114,3,0,0,0,114, + 3,0,0,0,114,6,0,0,0,218,23,95,102,105,110,100, + 95,112,97,114,101,110,116,95,112,97,116,104,95,110,97,109, + 101,115,112,4,0,0,115,8,0,0,0,0,2,18,1,8, + 2,4,3,122,38,95,78,97,109,101,115,112,97,99,101,80, + 97,116,104,46,95,102,105,110,100,95,112,97,114,101,110,116, + 95,112,97,116,104,95,110,97,109,101,115,99,1,0,0,0, + 0,0,0,0,3,0,0,0,3,0,0,0,67,0,0,0, + 115,28,0,0,0,124,0,160,0,161,0,92,2,125,1,125, + 2,116,1,116,2,106,3,124,1,25,0,124,2,131,2,83, + 0,114,110,0,0,0,41,4,114,30,1,0,0,114,130,0, + 0,0,114,8,0,0,0,218,7,109,111,100,117,108,101,115, + 41,3,114,119,0,0,0,90,18,112,97,114,101,110,116,95, + 109,111,100,117,108,101,95,110,97,109,101,90,14,112,97,116, + 104,95,97,116,116,114,95,110,97,109,101,114,3,0,0,0, + 114,3,0,0,0,114,6,0,0,0,114,25,1,0,0,122, + 4,0,0,115,4,0,0,0,0,1,12,1,122,31,95,78, + 97,109,101,115,112,97,99,101,80,97,116,104,46,95,103,101, + 116,95,112,97,114,101,110,116,95,112,97,116,104,99,1,0, + 0,0,0,0,0,0,3,0,0,0,4,0,0,0,67,0, + 0,0,115,80,0,0,0,116,0,124,0,160,1,161,0,131, + 1,125,1,124,1,124,0,106,2,107,3,114,74,124,0,160, + 3,124,0,106,4,124,1,161,2,125,2,124,2,100,0,107, + 9,114,68,124,2,106,5,100,0,107,8,114,68,124,2,106, + 6,114,68,124,2,106,6,124,0,95,7,124,1,124,0,95, + 2,124,0,106,7,83,0,114,110,0,0,0,41,8,114,112, + 0,0,0,114,25,1,0,0,114,26,1,0,0,114,27,1, + 0,0,114,23,1,0,0,114,140,0,0,0,114,178,0,0, + 0,114,24,1,0,0,41,3,114,119,0,0,0,90,11,112, + 97,114,101,110,116,95,112,97,116,104,114,187,0,0,0,114, + 3,0,0,0,114,3,0,0,0,114,6,0,0,0,218,12, + 95,114,101,99,97,108,99,117,108,97,116,101,126,4,0,0, + 115,16,0,0,0,0,2,12,1,10,1,14,3,18,1,6, + 1,8,1,6,1,122,27,95,78,97,109,101,115,112,97,99, + 101,80,97,116,104,46,95,114,101,99,97,108,99,117,108,97, + 116,101,99,1,0,0,0,0,0,0,0,1,0,0,0,3, + 0,0,0,67,0,0,0,115,12,0,0,0,116,0,124,0, + 160,1,161,0,131,1,83,0,114,110,0,0,0,41,2,114, + 5,1,0,0,114,32,1,0,0,114,246,0,0,0,114,3, + 0,0,0,114,3,0,0,0,114,6,0,0,0,218,8,95, + 95,105,116,101,114,95,95,139,4,0,0,115,2,0,0,0, + 0,1,122,23,95,78,97,109,101,115,112,97,99,101,80,97, + 116,104,46,95,95,105,116,101,114,95,95,99,2,0,0,0, + 0,0,0,0,2,0,0,0,2,0,0,0,67,0,0,0, + 115,12,0,0,0,124,0,160,0,161,0,124,1,25,0,83, + 0,114,110,0,0,0,169,1,114,32,1,0,0,41,2,114, + 119,0,0,0,218,5,105,110,100,101,120,114,3,0,0,0, + 114,3,0,0,0,114,6,0,0,0,218,11,95,95,103,101, + 116,105,116,101,109,95,95,142,4,0,0,115,2,0,0,0, + 0,1,122,26,95,78,97,109,101,115,112,97,99,101,80,97, + 116,104,46,95,95,103,101,116,105,116,101,109,95,95,99,3, + 0,0,0,0,0,0,0,3,0,0,0,3,0,0,0,67, + 0,0,0,115,14,0,0,0,124,2,124,0,106,0,124,1, + 60,0,100,0,83,0,114,110,0,0,0,41,1,114,24,1, + 0,0,41,3,114,119,0,0,0,114,35,1,0,0,114,44, + 0,0,0,114,3,0,0,0,114,3,0,0,0,114,6,0, + 0,0,218,11,95,95,115,101,116,105,116,101,109,95,95,145, + 4,0,0,115,2,0,0,0,0,1,122,26,95,78,97,109, + 101,115,112,97,99,101,80,97,116,104,46,95,95,115,101,116, + 105,116,101,109,95,95,99,1,0,0,0,0,0,0,0,1, + 0,0,0,3,0,0,0,67,0,0,0,115,12,0,0,0, + 116,0,124,0,160,1,161,0,131,1,83,0,114,110,0,0, + 0,41,2,114,22,0,0,0,114,32,1,0,0,114,246,0, + 0,0,114,3,0,0,0,114,3,0,0,0,114,6,0,0, + 0,218,7,95,95,108,101,110,95,95,148,4,0,0,115,2, + 0,0,0,0,1,122,22,95,78,97,109,101,115,112,97,99, + 101,80,97,116,104,46,95,95,108,101,110,95,95,99,1,0, 0,0,0,0,0,0,1,0,0,0,3,0,0,0,67,0, - 0,0,115,12,0,0,0,116,0,124,0,160,1,161,0,131, - 1,83,0,114,110,0,0,0,41,2,114,22,0,0,0,114, - 32,1,0,0,114,246,0,0,0,114,3,0,0,0,114,3, - 0,0,0,114,6,0,0,0,218,7,95,95,108,101,110,95, - 95,145,4,0,0,115,2,0,0,0,0,1,122,22,95,78, - 97,109,101,115,112,97,99,101,80,97,116,104,46,95,95,108, - 101,110,95,95,99,1,0,0,0,0,0,0,0,1,0,0, - 0,3,0,0,0,67,0,0,0,115,12,0,0,0,100,1, - 160,0,124,0,106,1,161,1,83,0,41,2,78,122,20,95, - 78,97,109,101,115,112,97,99,101,80,97,116,104,40,123,33, - 114,125,41,41,2,114,62,0,0,0,114,24,1,0,0,114, - 246,0,0,0,114,3,0,0,0,114,3,0,0,0,114,6, - 0,0,0,218,8,95,95,114,101,112,114,95,95,148,4,0, - 0,115,2,0,0,0,0,1,122,23,95,78,97,109,101,115, - 112,97,99,101,80,97,116,104,46,95,95,114,101,112,114,95, - 95,99,2,0,0,0,0,0,0,0,2,0,0,0,3,0, - 0,0,67,0,0,0,115,12,0,0,0,124,1,124,0,160, - 0,161,0,107,6,83,0,114,110,0,0,0,41,1,114,32, - 1,0,0,169,2,114,119,0,0,0,218,4,105,116,101,109, - 114,3,0,0,0,114,3,0,0,0,114,6,0,0,0,218, - 12,95,95,99,111,110,116,97,105,110,115,95,95,151,4,0, - 0,115,2,0,0,0,0,1,122,27,95,78,97,109,101,115, - 112,97,99,101,80,97,116,104,46,95,95,99,111,110,116,97, - 105,110,115,95,95,99,2,0,0,0,0,0,0,0,2,0, - 0,0,3,0,0,0,67,0,0,0,115,16,0,0,0,124, - 0,106,0,160,1,124,1,161,1,1,0,100,0,83,0,114, - 110,0,0,0,41,2,114,24,1,0,0,114,186,0,0,0, - 114,38,1,0,0,114,3,0,0,0,114,3,0,0,0,114, - 6,0,0,0,114,186,0,0,0,154,4,0,0,115,2,0, - 0,0,0,1,122,21,95,78,97,109,101,115,112,97,99,101, - 80,97,116,104,46,97,112,112,101,110,100,78,41,14,114,125, - 0,0,0,114,124,0,0,0,114,126,0,0,0,114,127,0, - 0,0,114,209,0,0,0,114,30,1,0,0,114,25,1,0, - 0,114,32,1,0,0,114,33,1,0,0,114,35,1,0,0, - 114,36,1,0,0,114,37,1,0,0,114,40,1,0,0,114, - 186,0,0,0,114,3,0,0,0,114,3,0,0,0,114,3, - 0,0,0,114,6,0,0,0,114,22,1,0,0,99,4,0, - 0,115,22,0,0,0,8,1,4,6,8,6,8,10,8,4, - 8,13,8,3,8,3,8,3,8,3,8,3,114,22,1,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,3,0, - 0,0,64,0,0,0,115,80,0,0,0,101,0,90,1,100, - 0,90,2,100,1,100,2,132,0,90,3,101,4,100,3,100, - 4,132,0,131,1,90,5,100,5,100,6,132,0,90,6,100, - 7,100,8,132,0,90,7,100,9,100,10,132,0,90,8,100, - 11,100,12,132,0,90,9,100,13,100,14,132,0,90,10,100, - 15,100,16,132,0,90,11,100,17,83,0,41,18,218,16,95, - 78,97,109,101,115,112,97,99,101,76,111,97,100,101,114,99, - 4,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0, - 67,0,0,0,115,18,0,0,0,116,0,124,1,124,2,124, - 3,131,3,124,0,95,1,100,0,83,0,114,110,0,0,0, - 41,2,114,22,1,0,0,114,24,1,0,0,114,28,1,0, - 0,114,3,0,0,0,114,3,0,0,0,114,6,0,0,0, - 114,209,0,0,0,160,4,0,0,115,2,0,0,0,0,1, - 122,25,95,78,97,109,101,115,112,97,99,101,76,111,97,100, - 101,114,46,95,95,105,110,105,116,95,95,99,2,0,0,0, - 0,0,0,0,2,0,0,0,3,0,0,0,67,0,0,0, - 115,12,0,0,0,100,1,160,0,124,1,106,1,161,1,83, - 0,41,2,122,115,82,101,116,117,114,110,32,114,101,112,114, - 32,102,111,114,32,116,104,101,32,109,111,100,117,108,101,46, - 10,10,32,32,32,32,32,32,32,32,84,104,101,32,109,101, - 116,104,111,100,32,105,115,32,100,101,112,114,101,99,97,116, - 101,100,46,32,32,84,104,101,32,105,109,112,111,114,116,32, - 109,97,99,104,105,110,101,114,121,32,100,111,101,115,32,116, - 104,101,32,106,111,98,32,105,116,115,101,108,102,46,10,10, - 32,32,32,32,32,32,32,32,122,25,60,109,111,100,117,108, - 101,32,123,33,114,125,32,40,110,97,109,101,115,112,97,99, - 101,41,62,41,2,114,62,0,0,0,114,125,0,0,0,41, - 2,114,193,0,0,0,114,216,0,0,0,114,3,0,0,0, - 114,3,0,0,0,114,6,0,0,0,218,11,109,111,100,117, - 108,101,95,114,101,112,114,163,4,0,0,115,2,0,0,0, - 0,7,122,28,95,78,97,109,101,115,112,97,99,101,76,111, - 97,100,101,114,46,109,111,100,117,108,101,95,114,101,112,114, - 99,2,0,0,0,0,0,0,0,2,0,0,0,1,0,0, - 0,67,0,0,0,115,4,0,0,0,100,1,83,0,41,2, - 78,84,114,3,0,0,0,114,219,0,0,0,114,3,0,0, - 0,114,3,0,0,0,114,6,0,0,0,114,182,0,0,0, - 172,4,0,0,115,2,0,0,0,0,1,122,27,95,78,97, - 109,101,115,112,97,99,101,76,111,97,100,101,114,46,105,115, - 95,112,97,99,107,97,103,101,99,2,0,0,0,0,0,0, - 0,2,0,0,0,1,0,0,0,67,0,0,0,115,4,0, - 0,0,100,1,83,0,41,2,78,114,40,0,0,0,114,3, - 0,0,0,114,219,0,0,0,114,3,0,0,0,114,3,0, - 0,0,114,6,0,0,0,114,229,0,0,0,175,4,0,0, - 115,2,0,0,0,0,1,122,27,95,78,97,109,101,115,112, - 97,99,101,76,111,97,100,101,114,46,103,101,116,95,115,111, - 117,114,99,101,99,2,0,0,0,0,0,0,0,2,0,0, - 0,6,0,0,0,67,0,0,0,115,16,0,0,0,116,0, - 100,1,100,2,100,3,100,4,100,5,141,4,83,0,41,6, - 78,114,40,0,0,0,122,8,60,115,116,114,105,110,103,62, - 114,215,0,0,0,84,41,1,114,231,0,0,0,41,1,114, - 232,0,0,0,114,219,0,0,0,114,3,0,0,0,114,3, - 0,0,0,114,6,0,0,0,114,213,0,0,0,178,4,0, - 0,115,2,0,0,0,0,1,122,25,95,78,97,109,101,115, - 112,97,99,101,76,111,97,100,101,114,46,103,101,116,95,99, - 111,100,101,99,2,0,0,0,0,0,0,0,2,0,0,0, - 1,0,0,0,67,0,0,0,115,4,0,0,0,100,1,83, - 0,114,210,0,0,0,114,3,0,0,0,114,211,0,0,0, - 114,3,0,0,0,114,3,0,0,0,114,6,0,0,0,114, - 212,0,0,0,181,4,0,0,115,2,0,0,0,0,1,122, - 30,95,78,97,109,101,115,112,97,99,101,76,111,97,100,101, - 114,46,99,114,101,97,116,101,95,109,111,100,117,108,101,99, - 2,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0, - 67,0,0,0,115,4,0,0,0,100,0,83,0,114,110,0, - 0,0,114,3,0,0,0,114,252,0,0,0,114,3,0,0, - 0,114,3,0,0,0,114,6,0,0,0,114,217,0,0,0, - 184,4,0,0,115,2,0,0,0,0,1,122,28,95,78,97, - 109,101,115,112,97,99,101,76,111,97,100,101,114,46,101,120, - 101,99,95,109,111,100,117,108,101,99,2,0,0,0,0,0, - 0,0,2,0,0,0,4,0,0,0,67,0,0,0,115,26, - 0,0,0,116,0,160,1,100,1,124,0,106,2,161,2,1, - 0,116,0,160,3,124,0,124,1,161,2,83,0,41,2,122, - 98,76,111,97,100,32,97,32,110,97,109,101,115,112,97,99, - 101,32,109,111,100,117,108,101,46,10,10,32,32,32,32,32, - 32,32,32,84,104,105,115,32,109,101,116,104,111,100,32,105, - 115,32,100,101,112,114,101,99,97,116,101,100,46,32,32,85, - 115,101,32,101,120,101,99,95,109,111,100,117,108,101,40,41, - 32,105,110,115,116,101,97,100,46,10,10,32,32,32,32,32, - 32,32,32,122,38,110,97,109,101,115,112,97,99,101,32,109, - 111,100,117,108,101,32,108,111,97,100,101,100,32,119,105,116, - 104,32,112,97,116,104,32,123,33,114,125,41,4,114,134,0, - 0,0,114,149,0,0,0,114,24,1,0,0,114,218,0,0, + 0,0,115,12,0,0,0,100,1,160,0,124,0,106,1,161, + 1,83,0,41,2,78,122,20,95,78,97,109,101,115,112,97, + 99,101,80,97,116,104,40,123,33,114,125,41,41,2,114,62, + 0,0,0,114,24,1,0,0,114,246,0,0,0,114,3,0, + 0,0,114,3,0,0,0,114,6,0,0,0,218,8,95,95, + 114,101,112,114,95,95,151,4,0,0,115,2,0,0,0,0, + 1,122,23,95,78,97,109,101,115,112,97,99,101,80,97,116, + 104,46,95,95,114,101,112,114,95,95,99,2,0,0,0,0, + 0,0,0,2,0,0,0,3,0,0,0,67,0,0,0,115, + 12,0,0,0,124,1,124,0,160,0,161,0,107,6,83,0, + 114,110,0,0,0,114,34,1,0,0,169,2,114,119,0,0, + 0,218,4,105,116,101,109,114,3,0,0,0,114,3,0,0, + 0,114,6,0,0,0,218,12,95,95,99,111,110,116,97,105, + 110,115,95,95,154,4,0,0,115,2,0,0,0,0,1,122, + 27,95,78,97,109,101,115,112,97,99,101,80,97,116,104,46, + 95,95,99,111,110,116,97,105,110,115,95,95,99,2,0,0, + 0,0,0,0,0,2,0,0,0,3,0,0,0,67,0,0, + 0,115,16,0,0,0,124,0,106,0,160,1,124,1,161,1, + 1,0,100,0,83,0,114,110,0,0,0,41,2,114,24,1, + 0,0,114,186,0,0,0,114,40,1,0,0,114,3,0,0, + 0,114,3,0,0,0,114,6,0,0,0,114,186,0,0,0, + 157,4,0,0,115,2,0,0,0,0,1,122,21,95,78,97, + 109,101,115,112,97,99,101,80,97,116,104,46,97,112,112,101, + 110,100,78,41,15,114,125,0,0,0,114,124,0,0,0,114, + 126,0,0,0,114,127,0,0,0,114,209,0,0,0,114,30, + 1,0,0,114,25,1,0,0,114,32,1,0,0,114,33,1, + 0,0,114,36,1,0,0,114,37,1,0,0,114,38,1,0, + 0,114,39,1,0,0,114,42,1,0,0,114,186,0,0,0, + 114,3,0,0,0,114,3,0,0,0,114,3,0,0,0,114, + 6,0,0,0,114,22,1,0,0,99,4,0,0,115,24,0, + 0,0,8,1,4,6,8,6,8,10,8,4,8,13,8,3, + 8,3,8,3,8,3,8,3,8,3,114,22,1,0,0,99, + 0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0, + 64,0,0,0,115,80,0,0,0,101,0,90,1,100,0,90, + 2,100,1,100,2,132,0,90,3,101,4,100,3,100,4,132, + 0,131,1,90,5,100,5,100,6,132,0,90,6,100,7,100, + 8,132,0,90,7,100,9,100,10,132,0,90,8,100,11,100, + 12,132,0,90,9,100,13,100,14,132,0,90,10,100,15,100, + 16,132,0,90,11,100,17,83,0,41,18,218,16,95,78,97, + 109,101,115,112,97,99,101,76,111,97,100,101,114,99,4,0, + 0,0,0,0,0,0,4,0,0,0,4,0,0,0,67,0, + 0,0,115,18,0,0,0,116,0,124,1,124,2,124,3,131, + 3,124,0,95,1,100,0,83,0,114,110,0,0,0,41,2, + 114,22,1,0,0,114,24,1,0,0,114,28,1,0,0,114, + 3,0,0,0,114,3,0,0,0,114,6,0,0,0,114,209, + 0,0,0,163,4,0,0,115,2,0,0,0,0,1,122,25, + 95,78,97,109,101,115,112,97,99,101,76,111,97,100,101,114, + 46,95,95,105,110,105,116,95,95,99,2,0,0,0,0,0, + 0,0,2,0,0,0,3,0,0,0,67,0,0,0,115,12, + 0,0,0,100,1,160,0,124,1,106,1,161,1,83,0,41, + 2,122,115,82,101,116,117,114,110,32,114,101,112,114,32,102, + 111,114,32,116,104,101,32,109,111,100,117,108,101,46,10,10, + 32,32,32,32,32,32,32,32,84,104,101,32,109,101,116,104, + 111,100,32,105,115,32,100,101,112,114,101,99,97,116,101,100, + 46,32,32,84,104,101,32,105,109,112,111,114,116,32,109,97, + 99,104,105,110,101,114,121,32,100,111,101,115,32,116,104,101, + 32,106,111,98,32,105,116,115,101,108,102,46,10,10,32,32, + 32,32,32,32,32,32,122,25,60,109,111,100,117,108,101,32, + 123,33,114,125,32,40,110,97,109,101,115,112,97,99,101,41, + 62,41,2,114,62,0,0,0,114,125,0,0,0,41,2,114, + 193,0,0,0,114,216,0,0,0,114,3,0,0,0,114,3, + 0,0,0,114,6,0,0,0,218,11,109,111,100,117,108,101, + 95,114,101,112,114,166,4,0,0,115,2,0,0,0,0,7, + 122,28,95,78,97,109,101,115,112,97,99,101,76,111,97,100, + 101,114,46,109,111,100,117,108,101,95,114,101,112,114,99,2, + 0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,67, + 0,0,0,115,4,0,0,0,100,1,83,0,41,2,78,84, + 114,3,0,0,0,114,219,0,0,0,114,3,0,0,0,114, + 3,0,0,0,114,6,0,0,0,114,182,0,0,0,175,4, + 0,0,115,2,0,0,0,0,1,122,27,95,78,97,109,101, + 115,112,97,99,101,76,111,97,100,101,114,46,105,115,95,112, + 97,99,107,97,103,101,99,2,0,0,0,0,0,0,0,2, + 0,0,0,1,0,0,0,67,0,0,0,115,4,0,0,0, + 100,1,83,0,41,2,78,114,40,0,0,0,114,3,0,0, 0,114,219,0,0,0,114,3,0,0,0,114,3,0,0,0, - 114,6,0,0,0,114,220,0,0,0,187,4,0,0,115,8, - 0,0,0,0,7,6,1,4,255,4,2,122,28,95,78,97, - 109,101,115,112,97,99,101,76,111,97,100,101,114,46,108,111, - 97,100,95,109,111,100,117,108,101,78,41,12,114,125,0,0, - 0,114,124,0,0,0,114,126,0,0,0,114,209,0,0,0, - 114,207,0,0,0,114,42,1,0,0,114,182,0,0,0,114, - 229,0,0,0,114,213,0,0,0,114,212,0,0,0,114,217, - 0,0,0,114,220,0,0,0,114,3,0,0,0,114,3,0, - 0,0,114,3,0,0,0,114,6,0,0,0,114,41,1,0, - 0,159,4,0,0,115,18,0,0,0,8,1,8,3,2,1, - 10,8,8,3,8,3,8,3,8,3,8,3,114,41,1,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,4,0, - 0,0,64,0,0,0,115,106,0,0,0,101,0,90,1,100, - 0,90,2,100,1,90,3,101,4,100,2,100,3,132,0,131, - 1,90,5,101,4,100,4,100,5,132,0,131,1,90,6,101, - 4,100,6,100,7,132,0,131,1,90,7,101,4,100,8,100, - 9,132,0,131,1,90,8,101,4,100,17,100,11,100,12,132, - 1,131,1,90,9,101,4,100,18,100,13,100,14,132,1,131, - 1,90,10,101,4,100,19,100,15,100,16,132,1,131,1,90, - 11,100,10,83,0,41,20,218,10,80,97,116,104,70,105,110, - 100,101,114,122,62,77,101,116,97,32,112,97,116,104,32,102, - 105,110,100,101,114,32,102,111,114,32,115,121,115,46,112,97, - 116,104,32,97,110,100,32,112,97,99,107,97,103,101,32,95, - 95,112,97,116,104,95,95,32,97,116,116,114,105,98,117,116, - 101,115,46,99,1,0,0,0,0,0,0,0,3,0,0,0, - 4,0,0,0,67,0,0,0,115,64,0,0,0,116,0,116, - 1,106,2,160,3,161,0,131,1,68,0,93,44,92,2,125, - 1,125,2,124,2,100,1,107,8,114,40,116,1,106,2,124, - 1,61,0,113,14,116,4,124,2,100,2,131,2,114,14,124, - 2,160,5,161,0,1,0,113,14,100,1,83,0,41,3,122, - 125,67,97,108,108,32,116,104,101,32,105,110,118,97,108,105, - 100,97,116,101,95,99,97,99,104,101,115,40,41,32,109,101, - 116,104,111,100,32,111,110,32,97,108,108,32,112,97,116,104, - 32,101,110,116,114,121,32,102,105,110,100,101,114,115,10,32, - 32,32,32,32,32,32,32,115,116,111,114,101,100,32,105,110, - 32,115,121,115,46,112,97,116,104,95,105,109,112,111,114,116, - 101,114,95,99,97,99,104,101,115,32,40,119,104,101,114,101, - 32,105,109,112,108,101,109,101,110,116,101,100,41,46,78,218, - 17,105,110,118,97,108,105,100,97,116,101,95,99,97,99,104, - 101,115,41,6,218,4,108,105,115,116,114,8,0,0,0,218, - 19,112,97,116,104,95,105,109,112,111,114,116,101,114,95,99, - 97,99,104,101,218,5,105,116,101,109,115,114,128,0,0,0, - 114,44,1,0,0,41,3,114,193,0,0,0,114,117,0,0, - 0,218,6,102,105,110,100,101,114,114,3,0,0,0,114,3, - 0,0,0,114,6,0,0,0,114,44,1,0,0,205,4,0, - 0,115,10,0,0,0,0,4,22,1,8,1,10,1,10,1, - 122,28,80,97,116,104,70,105,110,100,101,114,46,105,110,118, - 97,108,105,100,97,116,101,95,99,97,99,104,101,115,99,2, - 0,0,0,0,0,0,0,3,0,0,0,9,0,0,0,67, - 0,0,0,115,84,0,0,0,116,0,106,1,100,1,107,9, - 114,28,116,0,106,1,115,28,116,2,160,3,100,2,116,4, - 161,2,1,0,116,0,106,1,68,0,93,44,125,2,122,14, - 124,2,124,1,131,1,87,0,2,0,1,0,83,0,4,0, - 116,5,107,10,114,76,1,0,1,0,1,0,89,0,113,34, - 89,0,113,34,88,0,113,34,100,1,83,0,41,3,122,46, - 83,101,97,114,99,104,32,115,121,115,46,112,97,116,104,95, - 104,111,111,107,115,32,102,111,114,32,97,32,102,105,110,100, - 101,114,32,102,111,114,32,39,112,97,116,104,39,46,78,122, - 23,115,121,115,46,112,97,116,104,95,104,111,111,107,115,32, - 105,115,32,101,109,112,116,121,41,6,114,8,0,0,0,218, - 10,112,97,116,104,95,104,111,111,107,115,114,75,0,0,0, - 114,76,0,0,0,114,138,0,0,0,114,118,0,0,0,41, - 3,114,193,0,0,0,114,44,0,0,0,90,4,104,111,111, - 107,114,3,0,0,0,114,3,0,0,0,114,6,0,0,0, - 218,11,95,112,97,116,104,95,104,111,111,107,115,215,4,0, - 0,115,16,0,0,0,0,3,16,1,12,1,10,1,2,1, - 14,1,14,1,12,2,122,22,80,97,116,104,70,105,110,100, - 101,114,46,95,112,97,116,104,95,104,111,111,107,115,99,2, - 0,0,0,0,0,0,0,3,0,0,0,8,0,0,0,67, - 0,0,0,115,104,0,0,0,124,1,100,1,107,2,114,44, - 122,12,116,0,160,1,161,0,125,1,87,0,110,22,4,0, - 116,2,107,10,114,42,1,0,1,0,1,0,89,0,100,2, - 83,0,88,0,122,14,116,3,106,4,124,1,25,0,125,2, - 87,0,110,40,4,0,116,5,107,10,114,98,1,0,1,0, - 1,0,124,0,160,6,124,1,161,1,125,2,124,2,116,3, - 106,4,124,1,60,0,89,0,110,2,88,0,124,2,83,0, - 41,3,122,210,71,101,116,32,116,104,101,32,102,105,110,100, - 101,114,32,102,111,114,32,116,104,101,32,112,97,116,104,32, - 101,110,116,114,121,32,102,114,111,109,32,115,121,115,46,112, + 114,6,0,0,0,114,229,0,0,0,178,4,0,0,115,2, + 0,0,0,0,1,122,27,95,78,97,109,101,115,112,97,99, + 101,76,111,97,100,101,114,46,103,101,116,95,115,111,117,114, + 99,101,99,2,0,0,0,0,0,0,0,2,0,0,0,6, + 0,0,0,67,0,0,0,115,16,0,0,0,116,0,100,1, + 100,2,100,3,100,4,100,5,141,4,83,0,41,6,78,114, + 40,0,0,0,122,8,60,115,116,114,105,110,103,62,114,215, + 0,0,0,84,41,1,114,231,0,0,0,41,1,114,232,0, + 0,0,114,219,0,0,0,114,3,0,0,0,114,3,0,0, + 0,114,6,0,0,0,114,213,0,0,0,181,4,0,0,115, + 2,0,0,0,0,1,122,25,95,78,97,109,101,115,112,97, + 99,101,76,111,97,100,101,114,46,103,101,116,95,99,111,100, + 101,99,2,0,0,0,0,0,0,0,2,0,0,0,1,0, + 0,0,67,0,0,0,115,4,0,0,0,100,1,83,0,114, + 210,0,0,0,114,3,0,0,0,114,211,0,0,0,114,3, + 0,0,0,114,3,0,0,0,114,6,0,0,0,114,212,0, + 0,0,184,4,0,0,115,2,0,0,0,0,1,122,30,95, + 78,97,109,101,115,112,97,99,101,76,111,97,100,101,114,46, + 99,114,101,97,116,101,95,109,111,100,117,108,101,99,2,0, + 0,0,0,0,0,0,2,0,0,0,1,0,0,0,67,0, + 0,0,115,4,0,0,0,100,0,83,0,114,110,0,0,0, + 114,3,0,0,0,114,252,0,0,0,114,3,0,0,0,114, + 3,0,0,0,114,6,0,0,0,114,217,0,0,0,187,4, + 0,0,115,2,0,0,0,0,1,122,28,95,78,97,109,101, + 115,112,97,99,101,76,111,97,100,101,114,46,101,120,101,99, + 95,109,111,100,117,108,101,99,2,0,0,0,0,0,0,0, + 2,0,0,0,4,0,0,0,67,0,0,0,115,26,0,0, + 0,116,0,160,1,100,1,124,0,106,2,161,2,1,0,116, + 0,160,3,124,0,124,1,161,2,83,0,41,2,122,98,76, + 111,97,100,32,97,32,110,97,109,101,115,112,97,99,101,32, + 109,111,100,117,108,101,46,10,10,32,32,32,32,32,32,32, + 32,84,104,105,115,32,109,101,116,104,111,100,32,105,115,32, + 100,101,112,114,101,99,97,116,101,100,46,32,32,85,115,101, + 32,101,120,101,99,95,109,111,100,117,108,101,40,41,32,105, + 110,115,116,101,97,100,46,10,10,32,32,32,32,32,32,32, + 32,122,38,110,97,109,101,115,112,97,99,101,32,109,111,100, + 117,108,101,32,108,111,97,100,101,100,32,119,105,116,104,32, + 112,97,116,104,32,123,33,114,125,41,4,114,134,0,0,0, + 114,149,0,0,0,114,24,1,0,0,114,218,0,0,0,114, + 219,0,0,0,114,3,0,0,0,114,3,0,0,0,114,6, + 0,0,0,114,220,0,0,0,190,4,0,0,115,8,0,0, + 0,0,7,6,1,4,255,4,2,122,28,95,78,97,109,101, + 115,112,97,99,101,76,111,97,100,101,114,46,108,111,97,100, + 95,109,111,100,117,108,101,78,41,12,114,125,0,0,0,114, + 124,0,0,0,114,126,0,0,0,114,209,0,0,0,114,207, + 0,0,0,114,44,1,0,0,114,182,0,0,0,114,229,0, + 0,0,114,213,0,0,0,114,212,0,0,0,114,217,0,0, + 0,114,220,0,0,0,114,3,0,0,0,114,3,0,0,0, + 114,3,0,0,0,114,6,0,0,0,114,43,1,0,0,162, + 4,0,0,115,18,0,0,0,8,1,8,3,2,1,10,8, + 8,3,8,3,8,3,8,3,8,3,114,43,1,0,0,99, + 0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0, + 64,0,0,0,115,106,0,0,0,101,0,90,1,100,0,90, + 2,100,1,90,3,101,4,100,2,100,3,132,0,131,1,90, + 5,101,4,100,4,100,5,132,0,131,1,90,6,101,4,100, + 6,100,7,132,0,131,1,90,7,101,4,100,8,100,9,132, + 0,131,1,90,8,101,4,100,17,100,11,100,12,132,1,131, + 1,90,9,101,4,100,18,100,13,100,14,132,1,131,1,90, + 10,101,4,100,19,100,15,100,16,132,1,131,1,90,11,100, + 10,83,0,41,20,218,10,80,97,116,104,70,105,110,100,101, + 114,122,62,77,101,116,97,32,112,97,116,104,32,102,105,110, + 100,101,114,32,102,111,114,32,115,121,115,46,112,97,116,104, + 32,97,110,100,32,112,97,99,107,97,103,101,32,95,95,112, + 97,116,104,95,95,32,97,116,116,114,105,98,117,116,101,115, + 46,99,1,0,0,0,0,0,0,0,3,0,0,0,4,0, + 0,0,67,0,0,0,115,64,0,0,0,116,0,116,1,106, + 2,160,3,161,0,131,1,68,0,93,44,92,2,125,1,125, + 2,124,2,100,1,107,8,114,40,116,1,106,2,124,1,61, + 0,113,14,116,4,124,2,100,2,131,2,114,14,124,2,160, + 5,161,0,1,0,113,14,100,1,83,0,41,3,122,125,67, + 97,108,108,32,116,104,101,32,105,110,118,97,108,105,100,97, + 116,101,95,99,97,99,104,101,115,40,41,32,109,101,116,104, + 111,100,32,111,110,32,97,108,108,32,112,97,116,104,32,101, + 110,116,114,121,32,102,105,110,100,101,114,115,10,32,32,32, + 32,32,32,32,32,115,116,111,114,101,100,32,105,110,32,115, + 121,115,46,112,97,116,104,95,105,109,112,111,114,116,101,114, + 95,99,97,99,104,101,115,32,40,119,104,101,114,101,32,105, + 109,112,108,101,109,101,110,116,101,100,41,46,78,218,17,105, + 110,118,97,108,105,100,97,116,101,95,99,97,99,104,101,115, + 41,6,218,4,108,105,115,116,114,8,0,0,0,218,19,112, 97,116,104,95,105,109,112,111,114,116,101,114,95,99,97,99, - 104,101,46,10,10,32,32,32,32,32,32,32,32,73,102,32, - 116,104,101,32,112,97,116,104,32,101,110,116,114,121,32,105, - 115,32,110,111,116,32,105,110,32,116,104,101,32,99,97,99, - 104,101,44,32,102,105,110,100,32,116,104,101,32,97,112,112, - 114,111,112,114,105,97,116,101,32,102,105,110,100,101,114,10, - 32,32,32,32,32,32,32,32,97,110,100,32,99,97,99,104, - 101,32,105,116,46,32,73,102,32,110,111,32,102,105,110,100, - 101,114,32,105,115,32,97,118,97,105,108,97,98,108,101,44, - 32,115,116,111,114,101,32,78,111,110,101,46,10,10,32,32, - 32,32,32,32,32,32,114,40,0,0,0,78,41,7,114,2, - 0,0,0,114,55,0,0,0,114,2,1,0,0,114,8,0, - 0,0,114,46,1,0,0,218,8,75,101,121,69,114,114,111, - 114,114,50,1,0,0,41,3,114,193,0,0,0,114,44,0, - 0,0,114,48,1,0,0,114,3,0,0,0,114,3,0,0, - 0,114,6,0,0,0,218,20,95,112,97,116,104,95,105,109, - 112,111,114,116,101,114,95,99,97,99,104,101,228,4,0,0, - 115,22,0,0,0,0,8,8,1,2,1,12,1,14,3,8, - 1,2,1,14,1,14,1,10,1,16,1,122,31,80,97,116, - 104,70,105,110,100,101,114,46,95,112,97,116,104,95,105,109, - 112,111,114,116,101,114,95,99,97,99,104,101,99,3,0,0, - 0,0,0,0,0,6,0,0,0,4,0,0,0,67,0,0, - 0,115,82,0,0,0,116,0,124,2,100,1,131,2,114,26, - 124,2,160,1,124,1,161,1,92,2,125,3,125,4,110,14, - 124,2,160,2,124,1,161,1,125,3,103,0,125,4,124,3, - 100,0,107,9,114,60,116,3,160,4,124,1,124,3,161,2, - 83,0,116,3,160,5,124,1,100,0,161,2,125,5,124,4, - 124,5,95,6,124,5,83,0,41,2,78,114,137,0,0,0, - 41,7,114,128,0,0,0,114,137,0,0,0,114,206,0,0, - 0,114,134,0,0,0,114,201,0,0,0,114,183,0,0,0, - 114,178,0,0,0,41,6,114,193,0,0,0,114,139,0,0, - 0,114,48,1,0,0,114,140,0,0,0,114,141,0,0,0, - 114,187,0,0,0,114,3,0,0,0,114,3,0,0,0,114, - 6,0,0,0,218,16,95,108,101,103,97,99,121,95,103,101, - 116,95,115,112,101,99,250,4,0,0,115,18,0,0,0,0, - 4,10,1,16,2,10,1,4,1,8,1,12,1,12,1,6, - 1,122,27,80,97,116,104,70,105,110,100,101,114,46,95,108, - 101,103,97,99,121,95,103,101,116,95,115,112,101,99,78,99, - 4,0,0,0,0,0,0,0,9,0,0,0,5,0,0,0, - 67,0,0,0,115,166,0,0,0,103,0,125,4,124,2,68, - 0,93,134,125,5,116,0,124,5,116,1,116,2,102,2,131, - 2,115,28,113,8,124,0,160,3,124,5,161,1,125,6,124, - 6,100,1,107,9,114,8,116,4,124,6,100,2,131,2,114, - 70,124,6,160,5,124,1,124,3,161,2,125,7,110,12,124, - 0,160,6,124,1,124,6,161,2,125,7,124,7,100,1,107, - 8,114,92,113,8,124,7,106,7,100,1,107,9,114,110,124, - 7,2,0,1,0,83,0,124,7,106,8,125,8,124,8,100, - 1,107,8,114,132,116,9,100,3,131,1,130,1,124,4,160, - 10,124,8,161,1,1,0,113,8,116,11,160,12,124,1,100, - 1,161,2,125,7,124,4,124,7,95,8,124,7,83,0,41, - 4,122,63,70,105,110,100,32,116,104,101,32,108,111,97,100, - 101,114,32,111,114,32,110,97,109,101,115,112,97,99,101,95, - 112,97,116,104,32,102,111,114,32,116,104,105,115,32,109,111, - 100,117,108,101,47,112,97,99,107,97,103,101,32,110,97,109, - 101,46,78,114,203,0,0,0,122,19,115,112,101,99,32,109, - 105,115,115,105,110,103,32,108,111,97,100,101,114,41,13,114, - 161,0,0,0,114,85,0,0,0,218,5,98,121,116,101,115, - 114,52,1,0,0,114,128,0,0,0,114,203,0,0,0,114, - 53,1,0,0,114,140,0,0,0,114,178,0,0,0,114,118, - 0,0,0,114,167,0,0,0,114,134,0,0,0,114,183,0, - 0,0,41,9,114,193,0,0,0,114,139,0,0,0,114,44, - 0,0,0,114,202,0,0,0,218,14,110,97,109,101,115,112, - 97,99,101,95,112,97,116,104,90,5,101,110,116,114,121,114, - 48,1,0,0,114,187,0,0,0,114,141,0,0,0,114,3, - 0,0,0,114,3,0,0,0,114,6,0,0,0,218,9,95, - 103,101,116,95,115,112,101,99,9,5,0,0,115,40,0,0, - 0,0,5,4,1,8,1,14,1,2,1,10,1,8,1,10, - 1,14,2,12,1,8,1,2,1,10,1,8,1,6,1,8, - 1,8,5,12,2,12,1,6,1,122,20,80,97,116,104,70, - 105,110,100,101,114,46,95,103,101,116,95,115,112,101,99,99, - 4,0,0,0,0,0,0,0,6,0,0,0,5,0,0,0, - 67,0,0,0,115,100,0,0,0,124,2,100,1,107,8,114, - 14,116,0,106,1,125,2,124,0,160,2,124,1,124,2,124, - 3,161,3,125,4,124,4,100,1,107,8,114,40,100,1,83, - 0,124,4,106,3,100,1,107,8,114,92,124,4,106,4,125, - 5,124,5,114,86,100,1,124,4,95,5,116,6,124,1,124, - 5,124,0,106,2,131,3,124,4,95,4,124,4,83,0,100, - 1,83,0,110,4,124,4,83,0,100,1,83,0,41,2,122, - 141,84,114,121,32,116,111,32,102,105,110,100,32,97,32,115, - 112,101,99,32,102,111,114,32,39,102,117,108,108,110,97,109, - 101,39,32,111,110,32,115,121,115,46,112,97,116,104,32,111, - 114,32,39,112,97,116,104,39,46,10,10,32,32,32,32,32, - 32,32,32,84,104,101,32,115,101,97,114,99,104,32,105,115, - 32,98,97,115,101,100,32,111,110,32,115,121,115,46,112,97, - 116,104,95,104,111,111,107,115,32,97,110,100,32,115,121,115, - 46,112,97,116,104,95,105,109,112,111,114,116,101,114,95,99, - 97,99,104,101,46,10,32,32,32,32,32,32,32,32,78,41, - 7,114,8,0,0,0,114,44,0,0,0,114,56,1,0,0, - 114,140,0,0,0,114,178,0,0,0,114,181,0,0,0,114, - 22,1,0,0,41,6,114,193,0,0,0,114,139,0,0,0, - 114,44,0,0,0,114,202,0,0,0,114,187,0,0,0,114, - 55,1,0,0,114,3,0,0,0,114,3,0,0,0,114,6, - 0,0,0,114,203,0,0,0,41,5,0,0,115,26,0,0, - 0,0,6,8,1,6,1,14,1,8,1,4,1,10,1,6, - 1,4,3,6,1,16,1,4,2,6,2,122,20,80,97,116, - 104,70,105,110,100,101,114,46,102,105,110,100,95,115,112,101, - 99,99,3,0,0,0,0,0,0,0,4,0,0,0,4,0, - 0,0,67,0,0,0,115,30,0,0,0,124,0,160,0,124, - 1,124,2,161,2,125,3,124,3,100,1,107,8,114,24,100, - 1,83,0,124,3,106,1,83,0,41,2,122,170,102,105,110, - 100,32,116,104,101,32,109,111,100,117,108,101,32,111,110,32, - 115,121,115,46,112,97,116,104,32,111,114,32,39,112,97,116, - 104,39,32,98,97,115,101,100,32,111,110,32,115,121,115,46, - 112,97,116,104,95,104,111,111,107,115,32,97,110,100,10,32, - 32,32,32,32,32,32,32,115,121,115,46,112,97,116,104,95, - 105,109,112,111,114,116,101,114,95,99,97,99,104,101,46,10, - 10,32,32,32,32,32,32,32,32,84,104,105,115,32,109,101, - 116,104,111,100,32,105,115,32,100,101,112,114,101,99,97,116, - 101,100,46,32,32,85,115,101,32,102,105,110,100,95,115,112, - 101,99,40,41,32,105,110,115,116,101,97,100,46,10,10,32, - 32,32,32,32,32,32,32,78,114,204,0,0,0,114,205,0, - 0,0,114,3,0,0,0,114,3,0,0,0,114,6,0,0, - 0,114,206,0,0,0,65,5,0,0,115,8,0,0,0,0, - 8,12,1,8,1,4,1,122,22,80,97,116,104,70,105,110, - 100,101,114,46,102,105,110,100,95,109,111,100,117,108,101,41, - 1,78,41,2,78,78,41,1,78,41,12,114,125,0,0,0, - 114,124,0,0,0,114,126,0,0,0,114,127,0,0,0,114, - 207,0,0,0,114,44,1,0,0,114,50,1,0,0,114,52, - 1,0,0,114,53,1,0,0,114,56,1,0,0,114,203,0, - 0,0,114,206,0,0,0,114,3,0,0,0,114,3,0,0, - 0,114,3,0,0,0,114,6,0,0,0,114,43,1,0,0, - 201,4,0,0,115,30,0,0,0,8,2,4,2,2,1,10, - 9,2,1,10,12,2,1,10,21,2,1,10,14,2,1,12, - 31,2,1,12,23,2,1,114,43,1,0,0,99,0,0,0, - 0,0,0,0,0,0,0,0,0,3,0,0,0,64,0,0, - 0,115,90,0,0,0,101,0,90,1,100,0,90,2,100,1, - 90,3,100,2,100,3,132,0,90,4,100,4,100,5,132,0, - 90,5,101,6,90,7,100,6,100,7,132,0,90,8,100,8, - 100,9,132,0,90,9,100,19,100,11,100,12,132,1,90,10, - 100,13,100,14,132,0,90,11,101,12,100,15,100,16,132,0, - 131,1,90,13,100,17,100,18,132,0,90,14,100,10,83,0, - 41,20,218,10,70,105,108,101,70,105,110,100,101,114,122,172, - 70,105,108,101,45,98,97,115,101,100,32,102,105,110,100,101, - 114,46,10,10,32,32,32,32,73,110,116,101,114,97,99,116, - 105,111,110,115,32,119,105,116,104,32,116,104,101,32,102,105, - 108,101,32,115,121,115,116,101,109,32,97,114,101,32,99,97, - 99,104,101,100,32,102,111,114,32,112,101,114,102,111,114,109, - 97,110,99,101,44,32,98,101,105,110,103,10,32,32,32,32, - 114,101,102,114,101,115,104,101,100,32,119,104,101,110,32,116, - 104,101,32,100,105,114,101,99,116,111,114,121,32,116,104,101, - 32,102,105,110,100,101,114,32,105,115,32,104,97,110,100,108, - 105,110,103,32,104,97,115,32,98,101,101,110,32,109,111,100, - 105,102,105,101,100,46,10,10,32,32,32,32,99,2,0,0, - 0,0,0,0,0,5,0,0,0,6,0,0,0,7,0,0, - 0,115,84,0,0,0,103,0,125,3,124,2,68,0,93,32, - 92,2,137,0,125,4,124,3,160,0,135,0,102,1,100,1, - 100,2,132,8,124,4,68,0,131,1,161,1,1,0,113,8, - 124,3,124,0,95,1,124,1,112,54,100,3,124,0,95,2, - 100,4,124,0,95,3,116,4,131,0,124,0,95,5,116,4, - 131,0,124,0,95,6,100,5,83,0,41,6,122,154,73,110, - 105,116,105,97,108,105,122,101,32,119,105,116,104,32,116,104, - 101,32,112,97,116,104,32,116,111,32,115,101,97,114,99,104, - 32,111,110,32,97,110,100,32,97,32,118,97,114,105,97,98, - 108,101,32,110,117,109,98,101,114,32,111,102,10,32,32,32, - 32,32,32,32,32,50,45,116,117,112,108,101,115,32,99,111, - 110,116,97,105,110,105,110,103,32,116,104,101,32,108,111,97, - 100,101,114,32,97,110,100,32,116,104,101,32,102,105,108,101, - 32,115,117,102,102,105,120,101,115,32,116,104,101,32,108,111, - 97,100,101,114,10,32,32,32,32,32,32,32,32,114,101,99, - 111,103,110,105,122,101,115,46,99,1,0,0,0,0,0,0, - 0,2,0,0,0,3,0,0,0,51,0,0,0,115,22,0, - 0,0,124,0,93,14,125,1,124,1,136,0,102,2,86,0, - 1,0,113,2,100,0,83,0,114,110,0,0,0,114,3,0, - 0,0,114,16,1,0,0,169,1,114,140,0,0,0,114,3, - 0,0,0,114,6,0,0,0,114,19,1,0,0,94,5,0, - 0,115,4,0,0,0,4,0,2,0,122,38,70,105,108,101, - 70,105,110,100,101,114,46,95,95,105,110,105,116,95,95,46, - 60,108,111,99,97,108,115,62,46,60,103,101,110,101,120,112, - 114,62,114,71,0,0,0,114,105,0,0,0,78,41,7,114, - 167,0,0,0,218,8,95,108,111,97,100,101,114,115,114,44, - 0,0,0,218,11,95,112,97,116,104,95,109,116,105,109,101, - 218,3,115,101,116,218,11,95,112,97,116,104,95,99,97,99, - 104,101,218,19,95,114,101,108,97,120,101,100,95,112,97,116, - 104,95,99,97,99,104,101,41,5,114,119,0,0,0,114,44, - 0,0,0,218,14,108,111,97,100,101,114,95,100,101,116,97, - 105,108,115,90,7,108,111,97,100,101,114,115,114,189,0,0, - 0,114,3,0,0,0,114,58,1,0,0,114,6,0,0,0, - 114,209,0,0,0,88,5,0,0,115,16,0,0,0,0,4, - 4,1,12,1,26,1,6,2,10,1,6,1,8,1,122,19, - 70,105,108,101,70,105,110,100,101,114,46,95,95,105,110,105, - 116,95,95,99,1,0,0,0,0,0,0,0,1,0,0,0, - 2,0,0,0,67,0,0,0,115,10,0,0,0,100,1,124, - 0,95,0,100,2,83,0,41,3,122,31,73,110,118,97,108, - 105,100,97,116,101,32,116,104,101,32,100,105,114,101,99,116, - 111,114,121,32,109,116,105,109,101,46,114,105,0,0,0,78, - 41,1,114,60,1,0,0,114,246,0,0,0,114,3,0,0, - 0,114,3,0,0,0,114,6,0,0,0,114,44,1,0,0, - 102,5,0,0,115,2,0,0,0,0,2,122,28,70,105,108, - 101,70,105,110,100,101,114,46,105,110,118,97,108,105,100,97, - 116,101,95,99,97,99,104,101,115,99,2,0,0,0,0,0, - 0,0,3,0,0,0,3,0,0,0,67,0,0,0,115,42, - 0,0,0,124,0,160,0,124,1,161,1,125,2,124,2,100, - 1,107,8,114,26,100,1,103,0,102,2,83,0,124,2,106, - 1,124,2,106,2,112,38,103,0,102,2,83,0,41,2,122, - 197,84,114,121,32,116,111,32,102,105,110,100,32,97,32,108, - 111,97,100,101,114,32,102,111,114,32,116,104,101,32,115,112, - 101,99,105,102,105,101,100,32,109,111,100,117,108,101,44,32, - 111,114,32,116,104,101,32,110,97,109,101,115,112,97,99,101, - 10,32,32,32,32,32,32,32,32,112,97,99,107,97,103,101, - 32,112,111,114,116,105,111,110,115,46,32,82,101,116,117,114, - 110,115,32,40,108,111,97,100,101,114,44,32,108,105,115,116, - 45,111,102,45,112,111,114,116,105,111,110,115,41,46,10,10, - 32,32,32,32,32,32,32,32,84,104,105,115,32,109,101,116, - 104,111,100,32,105,115,32,100,101,112,114,101,99,97,116,101, - 100,46,32,32,85,115,101,32,102,105,110,100,95,115,112,101, - 99,40,41,32,105,110,115,116,101,97,100,46,10,10,32,32, - 32,32,32,32,32,32,78,41,3,114,203,0,0,0,114,140, - 0,0,0,114,178,0,0,0,41,3,114,119,0,0,0,114, - 139,0,0,0,114,187,0,0,0,114,3,0,0,0,114,3, - 0,0,0,114,6,0,0,0,114,137,0,0,0,108,5,0, - 0,115,8,0,0,0,0,7,10,1,8,1,8,1,122,22, - 70,105,108,101,70,105,110,100,101,114,46,102,105,110,100,95, - 108,111,97,100,101,114,99,6,0,0,0,0,0,0,0,7, - 0,0,0,6,0,0,0,67,0,0,0,115,26,0,0,0, - 124,1,124,2,124,3,131,2,125,6,116,0,124,2,124,3, - 124,6,124,4,100,1,141,4,83,0,41,2,78,114,177,0, - 0,0,41,1,114,190,0,0,0,41,7,114,119,0,0,0, - 114,188,0,0,0,114,139,0,0,0,114,44,0,0,0,90, - 4,115,109,115,108,114,202,0,0,0,114,140,0,0,0,114, - 3,0,0,0,114,3,0,0,0,114,6,0,0,0,114,56, - 1,0,0,120,5,0,0,115,8,0,0,0,0,1,10,1, - 8,1,2,255,122,20,70,105,108,101,70,105,110,100,101,114, - 46,95,103,101,116,95,115,112,101,99,78,99,3,0,0,0, - 0,0,0,0,14,0,0,0,8,0,0,0,67,0,0,0, - 115,102,1,0,0,100,1,125,3,124,1,160,0,100,2,161, - 1,100,3,25,0,125,4,122,24,116,1,124,0,106,2,112, - 34,116,3,160,4,161,0,131,1,106,5,125,5,87,0,110, - 24,4,0,116,6,107,10,114,66,1,0,1,0,1,0,100, - 4,125,5,89,0,110,2,88,0,124,5,124,0,106,7,107, - 3,114,92,124,0,160,8,161,0,1,0,124,5,124,0,95, - 7,116,9,131,0,114,114,124,0,106,10,125,6,124,4,160, - 11,161,0,125,7,110,10,124,0,106,12,125,6,124,4,125, - 7,124,7,124,6,107,6,114,218,116,13,124,0,106,2,124, - 4,131,2,125,8,124,0,106,14,68,0,93,58,92,2,125, - 9,125,10,100,5,124,9,23,0,125,11,116,13,124,8,124, - 11,131,2,125,12,116,15,124,12,131,1,114,208,124,0,160, - 16,124,10,124,1,124,12,124,8,103,1,124,2,161,5,2, - 0,1,0,83,0,113,150,116,17,124,8,131,1,125,3,124, - 0,106,14,68,0,93,86,92,2,125,9,125,10,116,13,124, - 0,106,2,124,4,124,9,23,0,131,2,125,12,116,18,106, - 19,100,6,124,12,100,3,100,7,141,3,1,0,124,7,124, - 9,23,0,124,6,107,6,144,1,114,54,116,15,124,12,131, - 1,144,1,114,54,124,0,160,16,124,10,124,1,124,12,100, - 8,124,2,161,5,2,0,1,0,83,0,113,224,124,3,144, - 1,114,98,116,18,160,19,100,9,124,8,161,2,1,0,116, - 18,160,20,124,1,100,8,161,2,125,13,124,8,103,1,124, - 13,95,21,124,13,83,0,100,8,83,0,41,10,122,111,84, + 104,101,218,5,105,116,101,109,115,114,128,0,0,0,114,46, + 1,0,0,41,3,114,193,0,0,0,114,117,0,0,0,218, + 6,102,105,110,100,101,114,114,3,0,0,0,114,3,0,0, + 0,114,6,0,0,0,114,46,1,0,0,208,4,0,0,115, + 10,0,0,0,0,4,22,1,8,1,10,1,10,1,122,28, + 80,97,116,104,70,105,110,100,101,114,46,105,110,118,97,108, + 105,100,97,116,101,95,99,97,99,104,101,115,99,2,0,0, + 0,0,0,0,0,3,0,0,0,9,0,0,0,67,0,0, + 0,115,84,0,0,0,116,0,106,1,100,1,107,9,114,28, + 116,0,106,1,115,28,116,2,160,3,100,2,116,4,161,2, + 1,0,116,0,106,1,68,0,93,44,125,2,122,14,124,2, + 124,1,131,1,87,0,2,0,1,0,83,0,4,0,116,5, + 107,10,114,76,1,0,1,0,1,0,89,0,113,34,89,0, + 113,34,88,0,113,34,100,1,83,0,41,3,122,46,83,101, + 97,114,99,104,32,115,121,115,46,112,97,116,104,95,104,111, + 111,107,115,32,102,111,114,32,97,32,102,105,110,100,101,114, + 32,102,111,114,32,39,112,97,116,104,39,46,78,122,23,115, + 121,115,46,112,97,116,104,95,104,111,111,107,115,32,105,115, + 32,101,109,112,116,121,41,6,114,8,0,0,0,218,10,112, + 97,116,104,95,104,111,111,107,115,114,75,0,0,0,114,76, + 0,0,0,114,138,0,0,0,114,118,0,0,0,41,3,114, + 193,0,0,0,114,44,0,0,0,90,4,104,111,111,107,114, + 3,0,0,0,114,3,0,0,0,114,6,0,0,0,218,11, + 95,112,97,116,104,95,104,111,111,107,115,218,4,0,0,115, + 16,0,0,0,0,3,16,1,12,1,10,1,2,1,14,1, + 14,1,12,2,122,22,80,97,116,104,70,105,110,100,101,114, + 46,95,112,97,116,104,95,104,111,111,107,115,99,2,0,0, + 0,0,0,0,0,3,0,0,0,8,0,0,0,67,0,0, + 0,115,104,0,0,0,124,1,100,1,107,2,114,44,122,12, + 116,0,160,1,161,0,125,1,87,0,110,22,4,0,116,2, + 107,10,114,42,1,0,1,0,1,0,89,0,100,2,83,0, + 88,0,122,14,116,3,106,4,124,1,25,0,125,2,87,0, + 110,40,4,0,116,5,107,10,114,98,1,0,1,0,1,0, + 124,0,160,6,124,1,161,1,125,2,124,2,116,3,106,4, + 124,1,60,0,89,0,110,2,88,0,124,2,83,0,41,3, + 122,210,71,101,116,32,116,104,101,32,102,105,110,100,101,114, + 32,102,111,114,32,116,104,101,32,112,97,116,104,32,101,110, + 116,114,121,32,102,114,111,109,32,115,121,115,46,112,97,116, + 104,95,105,109,112,111,114,116,101,114,95,99,97,99,104,101, + 46,10,10,32,32,32,32,32,32,32,32,73,102,32,116,104, + 101,32,112,97,116,104,32,101,110,116,114,121,32,105,115,32, + 110,111,116,32,105,110,32,116,104,101,32,99,97,99,104,101, + 44,32,102,105,110,100,32,116,104,101,32,97,112,112,114,111, + 112,114,105,97,116,101,32,102,105,110,100,101,114,10,32,32, + 32,32,32,32,32,32,97,110,100,32,99,97,99,104,101,32, + 105,116,46,32,73,102,32,110,111,32,102,105,110,100,101,114, + 32,105,115,32,97,118,97,105,108,97,98,108,101,44,32,115, + 116,111,114,101,32,78,111,110,101,46,10,10,32,32,32,32, + 32,32,32,32,114,40,0,0,0,78,41,7,114,2,0,0, + 0,114,55,0,0,0,114,2,1,0,0,114,8,0,0,0, + 114,48,1,0,0,218,8,75,101,121,69,114,114,111,114,114, + 52,1,0,0,41,3,114,193,0,0,0,114,44,0,0,0, + 114,50,1,0,0,114,3,0,0,0,114,3,0,0,0,114, + 6,0,0,0,218,20,95,112,97,116,104,95,105,109,112,111, + 114,116,101,114,95,99,97,99,104,101,231,4,0,0,115,22, + 0,0,0,0,8,8,1,2,1,12,1,14,3,8,1,2, + 1,14,1,14,1,10,1,16,1,122,31,80,97,116,104,70, + 105,110,100,101,114,46,95,112,97,116,104,95,105,109,112,111, + 114,116,101,114,95,99,97,99,104,101,99,3,0,0,0,0, + 0,0,0,6,0,0,0,4,0,0,0,67,0,0,0,115, + 82,0,0,0,116,0,124,2,100,1,131,2,114,26,124,2, + 160,1,124,1,161,1,92,2,125,3,125,4,110,14,124,2, + 160,2,124,1,161,1,125,3,103,0,125,4,124,3,100,0, + 107,9,114,60,116,3,160,4,124,1,124,3,161,2,83,0, + 116,3,160,5,124,1,100,0,161,2,125,5,124,4,124,5, + 95,6,124,5,83,0,41,2,78,114,137,0,0,0,41,7, + 114,128,0,0,0,114,137,0,0,0,114,206,0,0,0,114, + 134,0,0,0,114,201,0,0,0,114,183,0,0,0,114,178, + 0,0,0,41,6,114,193,0,0,0,114,139,0,0,0,114, + 50,1,0,0,114,140,0,0,0,114,141,0,0,0,114,187, + 0,0,0,114,3,0,0,0,114,3,0,0,0,114,6,0, + 0,0,218,16,95,108,101,103,97,99,121,95,103,101,116,95, + 115,112,101,99,253,4,0,0,115,18,0,0,0,0,4,10, + 1,16,2,10,1,4,1,8,1,12,1,12,1,6,1,122, + 27,80,97,116,104,70,105,110,100,101,114,46,95,108,101,103, + 97,99,121,95,103,101,116,95,115,112,101,99,78,99,4,0, + 0,0,0,0,0,0,9,0,0,0,5,0,0,0,67,0, + 0,0,115,166,0,0,0,103,0,125,4,124,2,68,0,93, + 134,125,5,116,0,124,5,116,1,116,2,102,2,131,2,115, + 28,113,8,124,0,160,3,124,5,161,1,125,6,124,6,100, + 1,107,9,114,8,116,4,124,6,100,2,131,2,114,70,124, + 6,160,5,124,1,124,3,161,2,125,7,110,12,124,0,160, + 6,124,1,124,6,161,2,125,7,124,7,100,1,107,8,114, + 92,113,8,124,7,106,7,100,1,107,9,114,110,124,7,2, + 0,1,0,83,0,124,7,106,8,125,8,124,8,100,1,107, + 8,114,132,116,9,100,3,131,1,130,1,124,4,160,10,124, + 8,161,1,1,0,113,8,116,11,160,12,124,1,100,1,161, + 2,125,7,124,4,124,7,95,8,124,7,83,0,41,4,122, + 63,70,105,110,100,32,116,104,101,32,108,111,97,100,101,114, + 32,111,114,32,110,97,109,101,115,112,97,99,101,95,112,97, + 116,104,32,102,111,114,32,116,104,105,115,32,109,111,100,117, + 108,101,47,112,97,99,107,97,103,101,32,110,97,109,101,46, + 78,114,203,0,0,0,122,19,115,112,101,99,32,109,105,115, + 115,105,110,103,32,108,111,97,100,101,114,41,13,114,161,0, + 0,0,114,85,0,0,0,218,5,98,121,116,101,115,114,54, + 1,0,0,114,128,0,0,0,114,203,0,0,0,114,55,1, + 0,0,114,140,0,0,0,114,178,0,0,0,114,118,0,0, + 0,114,167,0,0,0,114,134,0,0,0,114,183,0,0,0, + 41,9,114,193,0,0,0,114,139,0,0,0,114,44,0,0, + 0,114,202,0,0,0,218,14,110,97,109,101,115,112,97,99, + 101,95,112,97,116,104,90,5,101,110,116,114,121,114,50,1, + 0,0,114,187,0,0,0,114,141,0,0,0,114,3,0,0, + 0,114,3,0,0,0,114,6,0,0,0,218,9,95,103,101, + 116,95,115,112,101,99,12,5,0,0,115,40,0,0,0,0, + 5,4,1,8,1,14,1,2,1,10,1,8,1,10,1,14, + 2,12,1,8,1,2,1,10,1,8,1,6,1,8,1,8, + 5,12,2,12,1,6,1,122,20,80,97,116,104,70,105,110, + 100,101,114,46,95,103,101,116,95,115,112,101,99,99,4,0, + 0,0,0,0,0,0,6,0,0,0,5,0,0,0,67,0, + 0,0,115,100,0,0,0,124,2,100,1,107,8,114,14,116, + 0,106,1,125,2,124,0,160,2,124,1,124,2,124,3,161, + 3,125,4,124,4,100,1,107,8,114,40,100,1,83,0,124, + 4,106,3,100,1,107,8,114,92,124,4,106,4,125,5,124, + 5,114,86,100,1,124,4,95,5,116,6,124,1,124,5,124, + 0,106,2,131,3,124,4,95,4,124,4,83,0,100,1,83, + 0,110,4,124,4,83,0,100,1,83,0,41,2,122,141,84, 114,121,32,116,111,32,102,105,110,100,32,97,32,115,112,101, - 99,32,102,111,114,32,116,104,101,32,115,112,101,99,105,102, - 105,101,100,32,109,111,100,117,108,101,46,10,10,32,32,32, - 32,32,32,32,32,82,101,116,117,114,110,115,32,116,104,101, - 32,109,97,116,99,104,105,110,103,32,115,112,101,99,44,32, - 111,114,32,78,111,110,101,32,105,102,32,110,111,116,32,102, - 111,117,110,100,46,10,32,32,32,32,32,32,32,32,70,114, - 71,0,0,0,114,28,0,0,0,114,105,0,0,0,114,209, - 0,0,0,122,9,116,114,121,105,110,103,32,123,125,41,1, - 90,9,118,101,114,98,111,115,105,116,121,78,122,25,112,111, - 115,115,105,98,108,101,32,110,97,109,101,115,112,97,99,101, - 32,102,111,114,32,123,125,41,22,114,41,0,0,0,114,49, - 0,0,0,114,44,0,0,0,114,2,0,0,0,114,55,0, - 0,0,114,9,1,0,0,114,50,0,0,0,114,60,1,0, - 0,218,11,95,102,105,108,108,95,99,97,99,104,101,114,7, - 0,0,0,114,63,1,0,0,114,106,0,0,0,114,62,1, - 0,0,114,38,0,0,0,114,59,1,0,0,114,54,0,0, - 0,114,56,1,0,0,114,56,0,0,0,114,134,0,0,0, - 114,149,0,0,0,114,183,0,0,0,114,178,0,0,0,41, - 14,114,119,0,0,0,114,139,0,0,0,114,202,0,0,0, - 90,12,105,115,95,110,97,109,101,115,112,97,99,101,90,11, - 116,97,105,108,95,109,111,100,117,108,101,114,169,0,0,0, - 90,5,99,97,99,104,101,90,12,99,97,99,104,101,95,109, - 111,100,117,108,101,90,9,98,97,115,101,95,112,97,116,104, - 114,17,1,0,0,114,188,0,0,0,90,13,105,110,105,116, - 95,102,105,108,101,110,97,109,101,90,9,102,117,108,108,95, - 112,97,116,104,114,187,0,0,0,114,3,0,0,0,114,3, - 0,0,0,114,6,0,0,0,114,203,0,0,0,125,5,0, - 0,115,74,0,0,0,0,5,4,1,14,1,2,1,24,1, - 14,1,10,1,10,1,8,1,6,2,6,1,6,1,10,2, - 6,1,4,2,8,1,12,1,14,1,8,1,10,1,8,1, - 26,4,8,2,14,1,16,1,16,1,14,1,10,1,10,1, - 2,0,2,255,10,2,6,1,12,1,12,1,8,1,4,1, - 122,20,70,105,108,101,70,105,110,100,101,114,46,102,105,110, - 100,95,115,112,101,99,99,1,0,0,0,0,0,0,0,9, - 0,0,0,10,0,0,0,67,0,0,0,115,190,0,0,0, - 124,0,106,0,125,1,122,22,116,1,160,2,124,1,112,22, - 116,1,160,3,161,0,161,1,125,2,87,0,110,30,4,0, - 116,4,116,5,116,6,102,3,107,10,114,58,1,0,1,0, - 1,0,103,0,125,2,89,0,110,2,88,0,116,7,106,8, - 160,9,100,1,161,1,115,84,116,10,124,2,131,1,124,0, - 95,11,110,74,116,10,131,0,125,3,124,2,68,0,93,56, - 125,4,124,4,160,12,100,2,161,1,92,3,125,5,125,6, - 125,7,124,6,114,136,100,3,160,13,124,5,124,7,160,14, - 161,0,161,2,125,8,110,4,124,5,125,8,124,3,160,15, - 124,8,161,1,1,0,113,94,124,3,124,0,95,11,116,7, - 106,8,160,9,116,16,161,1,114,186,100,4,100,5,132,0, - 124,2,68,0,131,1,124,0,95,17,100,6,83,0,41,7, - 122,68,70,105,108,108,32,116,104,101,32,99,97,99,104,101, - 32,111,102,32,112,111,116,101,110,116,105,97,108,32,109,111, - 100,117,108,101,115,32,97,110,100,32,112,97,99,107,97,103, - 101,115,32,102,111,114,32,116,104,105,115,32,100,105,114,101, - 99,116,111,114,121,46,114,0,0,0,0,114,71,0,0,0, - 114,61,0,0,0,99,1,0,0,0,0,0,0,0,2,0, - 0,0,4,0,0,0,83,0,0,0,115,20,0,0,0,104, - 0,124,0,93,12,125,1,124,1,160,0,161,0,146,2,113, - 4,83,0,114,3,0,0,0,41,1,114,106,0,0,0,41, - 2,114,32,0,0,0,90,2,102,110,114,3,0,0,0,114, - 3,0,0,0,114,6,0,0,0,218,9,60,115,101,116,99, - 111,109,112,62,202,5,0,0,115,4,0,0,0,6,0,2, - 0,122,41,70,105,108,101,70,105,110,100,101,114,46,95,102, - 105,108,108,95,99,97,99,104,101,46,60,108,111,99,97,108, - 115,62,46,60,115,101,116,99,111,109,112,62,78,41,18,114, - 44,0,0,0,114,2,0,0,0,114,6,1,0,0,114,55, - 0,0,0,114,2,1,0,0,218,15,80,101,114,109,105,115, - 115,105,111,110,69,114,114,111,114,218,18,78,111,116,65,68, - 105,114,101,99,116,111,114,121,69,114,114,111,114,114,8,0, - 0,0,114,9,0,0,0,114,10,0,0,0,114,61,1,0, - 0,114,62,1,0,0,114,101,0,0,0,114,62,0,0,0, - 114,106,0,0,0,218,3,97,100,100,114,11,0,0,0,114, - 63,1,0,0,41,9,114,119,0,0,0,114,44,0,0,0, - 114,7,1,0,0,90,21,108,111,119,101,114,95,115,117,102, - 102,105,120,95,99,111,110,116,101,110,116,115,114,39,1,0, - 0,114,117,0,0,0,114,29,1,0,0,114,17,1,0,0, - 90,8,110,101,119,95,110,97,109,101,114,3,0,0,0,114, - 3,0,0,0,114,6,0,0,0,114,65,1,0,0,173,5, - 0,0,115,34,0,0,0,0,2,6,1,2,1,22,1,20, - 3,10,3,12,1,12,7,6,1,8,1,16,1,4,1,18, - 2,4,1,12,1,6,1,12,1,122,22,70,105,108,101,70, - 105,110,100,101,114,46,95,102,105,108,108,95,99,97,99,104, - 101,99,1,0,0,0,0,0,0,0,3,0,0,0,3,0, - 0,0,7,0,0,0,115,18,0,0,0,135,0,135,1,102, - 2,100,1,100,2,132,8,125,2,124,2,83,0,41,3,97, - 20,1,0,0,65,32,99,108,97,115,115,32,109,101,116,104, - 111,100,32,119,104,105,99,104,32,114,101,116,117,114,110,115, - 32,97,32,99,108,111,115,117,114,101,32,116,111,32,117,115, - 101,32,111,110,32,115,121,115,46,112,97,116,104,95,104,111, - 111,107,10,32,32,32,32,32,32,32,32,119,104,105,99,104, - 32,119,105,108,108,32,114,101,116,117,114,110,32,97,110,32, - 105,110,115,116,97,110,99,101,32,117,115,105,110,103,32,116, - 104,101,32,115,112,101,99,105,102,105,101,100,32,108,111,97, - 100,101,114,115,32,97,110,100,32,116,104,101,32,112,97,116, - 104,10,32,32,32,32,32,32,32,32,99,97,108,108,101,100, - 32,111,110,32,116,104,101,32,99,108,111,115,117,114,101,46, - 10,10,32,32,32,32,32,32,32,32,73,102,32,116,104,101, - 32,112,97,116,104,32,99,97,108,108,101,100,32,111,110,32, - 116,104,101,32,99,108,111,115,117,114,101,32,105,115,32,110, - 111,116,32,97,32,100,105,114,101,99,116,111,114,121,44,32, - 73,109,112,111,114,116,69,114,114,111,114,32,105,115,10,32, - 32,32,32,32,32,32,32,114,97,105,115,101,100,46,10,10, - 32,32,32,32,32,32,32,32,99,1,0,0,0,0,0,0, - 0,1,0,0,0,4,0,0,0,19,0,0,0,115,34,0, - 0,0,116,0,124,0,131,1,115,20,116,1,100,1,124,0, - 100,2,141,2,130,1,136,0,124,0,102,1,136,1,158,2, - 142,0,83,0,41,3,122,45,80,97,116,104,32,104,111,111, - 107,32,102,111,114,32,105,109,112,111,114,116,108,105,98,46, - 109,97,99,104,105,110,101,114,121,46,70,105,108,101,70,105, - 110,100,101,114,46,122,30,111,110,108,121,32,100,105,114,101, - 99,116,111,114,105,101,115,32,97,114,101,32,115,117,112,112, - 111,114,116,101,100,114,48,0,0,0,41,2,114,56,0,0, - 0,114,118,0,0,0,114,48,0,0,0,169,2,114,193,0, - 0,0,114,64,1,0,0,114,3,0,0,0,114,6,0,0, - 0,218,24,112,97,116,104,95,104,111,111,107,95,102,111,114, - 95,70,105,108,101,70,105,110,100,101,114,214,5,0,0,115, - 6,0,0,0,0,2,8,1,12,1,122,54,70,105,108,101, - 70,105,110,100,101,114,46,112,97,116,104,95,104,111,111,107, - 46,60,108,111,99,97,108,115,62,46,112,97,116,104,95,104, - 111,111,107,95,102,111,114,95,70,105,108,101,70,105,110,100, - 101,114,114,3,0,0,0,41,3,114,193,0,0,0,114,64, - 1,0,0,114,71,1,0,0,114,3,0,0,0,114,70,1, - 0,0,114,6,0,0,0,218,9,112,97,116,104,95,104,111, - 111,107,204,5,0,0,115,4,0,0,0,0,10,14,6,122, - 20,70,105,108,101,70,105,110,100,101,114,46,112,97,116,104, - 95,104,111,111,107,99,1,0,0,0,0,0,0,0,1,0, - 0,0,3,0,0,0,67,0,0,0,115,12,0,0,0,100, - 1,160,0,124,0,106,1,161,1,83,0,41,2,78,122,16, - 70,105,108,101,70,105,110,100,101,114,40,123,33,114,125,41, - 41,2,114,62,0,0,0,114,44,0,0,0,114,246,0,0, - 0,114,3,0,0,0,114,3,0,0,0,114,6,0,0,0, - 114,37,1,0,0,222,5,0,0,115,2,0,0,0,0,1, - 122,19,70,105,108,101,70,105,110,100,101,114,46,95,95,114, - 101,112,114,95,95,41,1,78,41,15,114,125,0,0,0,114, - 124,0,0,0,114,126,0,0,0,114,127,0,0,0,114,209, - 0,0,0,114,44,1,0,0,114,143,0,0,0,114,206,0, - 0,0,114,137,0,0,0,114,56,1,0,0,114,203,0,0, - 0,114,65,1,0,0,114,207,0,0,0,114,72,1,0,0, - 114,37,1,0,0,114,3,0,0,0,114,3,0,0,0,114, - 3,0,0,0,114,6,0,0,0,114,57,1,0,0,79,5, - 0,0,115,22,0,0,0,8,2,4,7,8,14,8,4,4, - 2,8,12,8,5,10,48,8,31,2,1,10,17,114,57,1, - 0,0,99,4,0,0,0,0,0,0,0,6,0,0,0,8, - 0,0,0,67,0,0,0,115,146,0,0,0,124,0,160,0, - 100,1,161,1,125,4,124,0,160,0,100,2,161,1,125,5, - 124,4,115,66,124,5,114,36,124,5,106,1,125,4,110,30, - 124,2,124,3,107,2,114,56,116,2,124,1,124,2,131,2, - 125,4,110,10,116,3,124,1,124,2,131,2,125,4,124,5, - 115,84,116,4,124,1,124,2,124,4,100,3,141,3,125,5, - 122,36,124,5,124,0,100,2,60,0,124,4,124,0,100,1, - 60,0,124,2,124,0,100,4,60,0,124,3,124,0,100,5, - 60,0,87,0,110,20,4,0,116,5,107,10,114,140,1,0, - 1,0,1,0,89,0,110,2,88,0,100,0,83,0,41,6, - 78,218,10,95,95,108,111,97,100,101,114,95,95,218,8,95, - 95,115,112,101,99,95,95,114,58,1,0,0,90,8,95,95, - 102,105,108,101,95,95,90,10,95,95,99,97,99,104,101,100, - 95,95,41,6,218,3,103,101,116,114,140,0,0,0,114,14, - 1,0,0,114,8,1,0,0,114,190,0,0,0,218,9,69, - 120,99,101,112,116,105,111,110,41,6,90,2,110,115,114,117, - 0,0,0,90,8,112,97,116,104,110,97,109,101,90,9,99, - 112,97,116,104,110,97,109,101,114,140,0,0,0,114,187,0, + 99,32,102,111,114,32,39,102,117,108,108,110,97,109,101,39, + 32,111,110,32,115,121,115,46,112,97,116,104,32,111,114,32, + 39,112,97,116,104,39,46,10,10,32,32,32,32,32,32,32, + 32,84,104,101,32,115,101,97,114,99,104,32,105,115,32,98, + 97,115,101,100,32,111,110,32,115,121,115,46,112,97,116,104, + 95,104,111,111,107,115,32,97,110,100,32,115,121,115,46,112, + 97,116,104,95,105,109,112,111,114,116,101,114,95,99,97,99, + 104,101,46,10,32,32,32,32,32,32,32,32,78,41,7,114, + 8,0,0,0,114,44,0,0,0,114,58,1,0,0,114,140, + 0,0,0,114,178,0,0,0,114,181,0,0,0,114,22,1, + 0,0,41,6,114,193,0,0,0,114,139,0,0,0,114,44, + 0,0,0,114,202,0,0,0,114,187,0,0,0,114,57,1, 0,0,114,3,0,0,0,114,3,0,0,0,114,6,0,0, - 0,218,14,95,102,105,120,95,117,112,95,109,111,100,117,108, - 101,228,5,0,0,115,34,0,0,0,0,2,10,1,10,1, - 4,1,4,1,8,1,8,1,12,2,10,1,4,1,14,1, - 2,1,8,1,8,1,8,1,12,1,14,2,114,77,1,0, - 0,99,0,0,0,0,0,0,0,0,3,0,0,0,3,0, - 0,0,67,0,0,0,115,38,0,0,0,116,0,116,1,160, - 2,161,0,102,2,125,0,116,3,116,4,102,2,125,1,116, - 5,116,6,102,2,125,2,124,0,124,1,124,2,103,3,83, - 0,41,1,122,95,82,101,116,117,114,110,115,32,97,32,108, - 105,115,116,32,111,102,32,102,105,108,101,45,98,97,115,101, - 100,32,109,111,100,117,108,101,32,108,111,97,100,101,114,115, - 46,10,10,32,32,32,32,69,97,99,104,32,105,116,101,109, - 32,105,115,32,97,32,116,117,112,108,101,32,40,108,111,97, - 100,101,114,44,32,115,117,102,102,105,120,101,115,41,46,10, - 32,32,32,32,41,7,114,15,1,0,0,114,163,0,0,0, - 218,18,101,120,116,101,110,115,105,111,110,95,115,117,102,102, - 105,120,101,115,114,8,1,0,0,114,102,0,0,0,114,14, - 1,0,0,114,89,0,0,0,41,3,90,10,101,120,116,101, - 110,115,105,111,110,115,90,6,115,111,117,114,99,101,90,8, - 98,121,116,101,99,111,100,101,114,3,0,0,0,114,3,0, - 0,0,114,6,0,0,0,114,184,0,0,0,251,5,0,0, - 115,8,0,0,0,0,5,12,1,8,1,8,1,114,184,0, - 0,0,99,1,0,0,0,0,0,0,0,12,0,0,0,9, - 0,0,0,67,0,0,0,115,178,1,0,0,124,0,97,0, - 116,0,106,1,97,1,116,0,106,2,97,2,116,1,106,3, - 116,4,25,0,125,1,100,1,68,0,93,48,125,2,124,2, - 116,1,106,3,107,7,114,56,116,0,160,5,124,2,161,1, - 125,3,110,10,116,1,106,3,124,2,25,0,125,3,116,6, - 124,1,124,2,124,3,131,3,1,0,113,30,100,2,100,3, - 103,1,102,2,100,4,100,5,100,3,103,2,102,2,102,2, - 125,4,124,4,68,0,93,110,92,2,125,5,125,6,116,7, - 100,6,100,7,132,0,124,6,68,0,131,1,131,1,115,136, - 116,8,130,1,124,6,100,8,25,0,125,7,124,5,116,1, - 106,3,107,6,114,170,116,1,106,3,124,5,25,0,125,8, - 1,0,113,226,113,106,122,20,116,0,160,5,124,5,161,1, - 125,8,87,0,1,0,113,226,87,0,113,106,4,0,116,9, - 107,10,114,214,1,0,1,0,1,0,89,0,113,106,89,0, - 113,106,88,0,113,106,116,9,100,9,131,1,130,1,116,6, - 124,1,100,10,124,8,131,3,1,0,116,6,124,1,100,11, - 124,7,131,3,1,0,116,6,124,1,100,12,100,13,160,10, - 124,6,161,1,131,3,1,0,116,6,124,1,100,14,100,15, - 100,16,132,0,124,6,68,0,131,1,131,3,1,0,116,0, - 160,5,100,17,161,1,125,9,116,6,124,1,100,17,124,9, - 131,3,1,0,116,0,160,5,100,18,161,1,125,10,116,6, - 124,1,100,18,124,10,131,3,1,0,124,5,100,4,107,2, - 144,1,114,110,116,0,160,5,100,19,161,1,125,11,116,6, - 124,1,100,20,124,11,131,3,1,0,116,6,124,1,100,21, - 116,11,131,0,131,3,1,0,116,12,160,13,116,2,160,14, - 161,0,161,1,1,0,124,5,100,4,107,2,144,1,114,174, - 116,15,160,16,100,22,161,1,1,0,100,23,116,12,107,6, - 144,1,114,174,100,24,116,17,95,18,100,25,83,0,41,26, - 122,205,83,101,116,117,112,32,116,104,101,32,112,97,116,104, - 45,98,97,115,101,100,32,105,109,112,111,114,116,101,114,115, - 32,102,111,114,32,105,109,112,111,114,116,108,105,98,32,98, - 121,32,105,109,112,111,114,116,105,110,103,32,110,101,101,100, - 101,100,10,32,32,32,32,98,117,105,108,116,45,105,110,32, - 109,111,100,117,108,101,115,32,97,110,100,32,105,110,106,101, - 99,116,105,110,103,32,116,104,101,109,32,105,110,116,111,32, - 116,104,101,32,103,108,111,98,97,108,32,110,97,109,101,115, - 112,97,99,101,46,10,10,32,32,32,32,79,116,104,101,114, - 32,99,111,109,112,111,110,101,110,116,115,32,97,114,101,32, - 101,120,116,114,97,99,116,101,100,32,102,114,111,109,32,116, - 104,101,32,99,111,114,101,32,98,111,111,116,115,116,114,97, - 112,32,109,111,100,117,108,101,46,10,10,32,32,32,32,41, - 4,114,64,0,0,0,114,75,0,0,0,218,8,98,117,105, - 108,116,105,110,115,114,160,0,0,0,90,5,112,111,115,105, - 120,250,1,47,90,2,110,116,250,1,92,99,1,0,0,0, - 0,0,0,0,2,0,0,0,3,0,0,0,115,0,0,0, - 115,26,0,0,0,124,0,93,18,125,1,116,0,124,1,131, - 1,100,0,107,2,86,0,1,0,113,2,100,1,83,0,41, - 2,114,39,0,0,0,78,41,1,114,22,0,0,0,41,2, - 114,32,0,0,0,114,95,0,0,0,114,3,0,0,0,114, - 3,0,0,0,114,6,0,0,0,114,19,1,0,0,31,6, - 0,0,115,4,0,0,0,4,0,2,0,122,25,95,115,101, - 116,117,112,46,60,108,111,99,97,108,115,62,46,60,103,101, - 110,101,120,112,114,62,114,73,0,0,0,122,30,105,109,112, - 111,114,116,108,105,98,32,114,101,113,117,105,114,101,115,32, - 112,111,115,105,120,32,111,114,32,110,116,114,2,0,0,0, - 114,35,0,0,0,114,31,0,0,0,114,40,0,0,0,114, - 58,0,0,0,99,1,0,0,0,0,0,0,0,2,0,0, - 0,4,0,0,0,83,0,0,0,115,22,0,0,0,104,0, - 124,0,93,14,125,1,100,0,124,1,155,0,157,2,146,2, - 113,4,83,0,41,1,114,74,0,0,0,114,3,0,0,0, - 41,2,114,32,0,0,0,218,1,115,114,3,0,0,0,114, - 3,0,0,0,114,6,0,0,0,114,66,1,0,0,47,6, - 0,0,115,4,0,0,0,6,0,2,0,122,25,95,115,101, - 116,117,112,46,60,108,111,99,97,108,115,62,46,60,115,101, - 116,99,111,109,112,62,90,7,95,116,104,114,101,97,100,90, - 8,95,119,101,97,107,114,101,102,90,6,119,105,110,114,101, - 103,114,192,0,0,0,114,7,0,0,0,122,4,46,112,121, - 119,122,6,95,100,46,112,121,100,84,78,41,19,114,134,0, - 0,0,114,8,0,0,0,114,163,0,0,0,114,31,1,0, - 0,114,125,0,0,0,90,18,95,98,117,105,108,116,105,110, - 95,102,114,111,109,95,110,97,109,101,114,129,0,0,0,218, - 3,97,108,108,114,23,0,0,0,114,118,0,0,0,114,36, - 0,0,0,114,13,0,0,0,114,21,1,0,0,114,167,0, - 0,0,114,78,1,0,0,114,102,0,0,0,114,186,0,0, - 0,114,191,0,0,0,114,195,0,0,0,41,12,218,17,95, - 98,111,111,116,115,116,114,97,112,95,109,111,100,117,108,101, - 90,11,115,101,108,102,95,109,111,100,117,108,101,90,12,98, - 117,105,108,116,105,110,95,110,97,109,101,90,14,98,117,105, - 108,116,105,110,95,109,111,100,117,108,101,90,10,111,115,95, - 100,101,116,97,105,108,115,90,10,98,117,105,108,116,105,110, - 95,111,115,114,31,0,0,0,114,35,0,0,0,90,9,111, - 115,95,109,111,100,117,108,101,90,13,116,104,114,101,97,100, - 95,109,111,100,117,108,101,90,14,119,101,97,107,114,101,102, - 95,109,111,100,117,108,101,90,13,119,105,110,114,101,103,95, - 109,111,100,117,108,101,114,3,0,0,0,114,3,0,0,0, - 114,6,0,0,0,218,6,95,115,101,116,117,112,6,6,0, - 0,115,78,0,0,0,0,8,4,1,6,1,6,3,10,1, - 8,1,10,1,12,2,10,1,14,3,22,1,12,2,22,1, - 8,1,10,1,10,1,6,2,2,1,10,1,10,1,14,1, - 12,2,8,1,12,1,12,1,18,1,22,3,10,1,12,3, - 10,1,12,3,10,1,10,1,12,3,14,1,14,1,10,1, - 10,1,10,1,114,85,1,0,0,99,1,0,0,0,0,0, - 0,0,2,0,0,0,4,0,0,0,67,0,0,0,115,50, - 0,0,0,116,0,124,0,131,1,1,0,116,1,131,0,125, - 1,116,2,106,3,160,4,116,5,106,6,124,1,142,0,103, - 1,161,1,1,0,116,2,106,7,160,8,116,9,161,1,1, - 0,100,1,83,0,41,2,122,41,73,110,115,116,97,108,108, - 32,116,104,101,32,112,97,116,104,45,98,97,115,101,100,32, - 105,109,112,111,114,116,32,99,111,109,112,111,110,101,110,116, - 115,46,78,41,10,114,85,1,0,0,114,184,0,0,0,114, - 8,0,0,0,114,49,1,0,0,114,167,0,0,0,114,57, - 1,0,0,114,72,1,0,0,218,9,109,101,116,97,95,112, - 97,116,104,114,186,0,0,0,114,43,1,0,0,41,2,114, - 84,1,0,0,90,17,115,117,112,112,111,114,116,101,100,95, - 108,111,97,100,101,114,115,114,3,0,0,0,114,3,0,0, - 0,114,6,0,0,0,218,8,95,105,110,115,116,97,108,108, - 71,6,0,0,115,8,0,0,0,0,2,8,1,6,1,20, - 1,114,87,1,0,0,41,63,114,127,0,0,0,114,12,0, - 0,0,90,37,95,67,65,83,69,95,73,78,83,69,78,83, - 73,84,73,86,69,95,80,76,65,84,70,79,82,77,83,95, - 66,89,84,69,83,95,75,69,89,114,11,0,0,0,114,13, - 0,0,0,114,20,0,0,0,114,27,0,0,0,114,29,0, - 0,0,114,38,0,0,0,114,47,0,0,0,114,49,0,0, - 0,114,53,0,0,0,114,54,0,0,0,114,56,0,0,0, - 114,59,0,0,0,114,69,0,0,0,218,4,116,121,112,101, - 218,8,95,95,99,111,100,101,95,95,114,162,0,0,0,114, - 18,0,0,0,114,148,0,0,0,114,17,0,0,0,114,24, - 0,0,0,114,236,0,0,0,114,92,0,0,0,114,88,0, - 0,0,114,102,0,0,0,114,89,0,0,0,90,23,68,69, - 66,85,71,95,66,89,84,69,67,79,68,69,95,83,85,70, - 70,73,88,69,83,90,27,79,80,84,73,77,73,90,69,68, - 95,66,89,84,69,67,79,68,69,95,83,85,70,70,73,88, - 69,83,114,98,0,0,0,114,103,0,0,0,114,109,0,0, - 0,114,113,0,0,0,114,115,0,0,0,114,136,0,0,0, - 114,143,0,0,0,114,152,0,0,0,114,156,0,0,0,114, - 158,0,0,0,114,165,0,0,0,114,170,0,0,0,114,171, - 0,0,0,114,176,0,0,0,218,6,111,98,106,101,99,116, - 114,185,0,0,0,114,190,0,0,0,114,191,0,0,0,114, - 208,0,0,0,114,221,0,0,0,114,239,0,0,0,114,8, - 1,0,0,114,14,1,0,0,114,21,1,0,0,114,15,1, - 0,0,114,22,1,0,0,114,41,1,0,0,114,43,1,0, - 0,114,57,1,0,0,114,77,1,0,0,114,184,0,0,0, - 114,85,1,0,0,114,87,1,0,0,114,3,0,0,0,114, - 3,0,0,0,114,3,0,0,0,114,6,0,0,0,218,8, - 60,109,111,100,117,108,101,62,1,0,0,0,115,126,0,0, - 0,4,22,4,1,4,1,2,1,2,255,4,4,8,17,8, - 5,8,5,8,6,8,6,8,12,8,10,8,9,8,5,8, - 7,8,9,12,22,10,127,0,7,16,1,12,2,4,1,4, - 2,6,2,6,2,8,2,18,71,8,40,8,19,8,12,8, - 12,8,28,8,17,8,33,8,28,8,24,16,13,14,10,12, - 11,8,14,6,3,6,1,2,255,12,68,14,64,14,29,16, - 127,0,17,14,68,18,45,18,26,4,3,18,53,14,60,14, - 42,14,127,0,7,14,127,0,22,12,23,8,11,8,65, + 0,114,203,0,0,0,44,5,0,0,115,26,0,0,0,0, + 6,8,1,6,1,14,1,8,1,4,1,10,1,6,1,4, + 3,6,1,16,1,4,2,6,2,122,20,80,97,116,104,70, + 105,110,100,101,114,46,102,105,110,100,95,115,112,101,99,99, + 3,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0, + 67,0,0,0,115,30,0,0,0,124,0,160,0,124,1,124, + 2,161,2,125,3,124,3,100,1,107,8,114,24,100,1,83, + 0,124,3,106,1,83,0,41,2,122,170,102,105,110,100,32, + 116,104,101,32,109,111,100,117,108,101,32,111,110,32,115,121, + 115,46,112,97,116,104,32,111,114,32,39,112,97,116,104,39, + 32,98,97,115,101,100,32,111,110,32,115,121,115,46,112,97, + 116,104,95,104,111,111,107,115,32,97,110,100,10,32,32,32, + 32,32,32,32,32,115,121,115,46,112,97,116,104,95,105,109, + 112,111,114,116,101,114,95,99,97,99,104,101,46,10,10,32, + 32,32,32,32,32,32,32,84,104,105,115,32,109,101,116,104, + 111,100,32,105,115,32,100,101,112,114,101,99,97,116,101,100, + 46,32,32,85,115,101,32,102,105,110,100,95,115,112,101,99, + 40,41,32,105,110,115,116,101,97,100,46,10,10,32,32,32, + 32,32,32,32,32,78,114,204,0,0,0,114,205,0,0,0, + 114,3,0,0,0,114,3,0,0,0,114,6,0,0,0,114, + 206,0,0,0,68,5,0,0,115,8,0,0,0,0,8,12, + 1,8,1,4,1,122,22,80,97,116,104,70,105,110,100,101, + 114,46,102,105,110,100,95,109,111,100,117,108,101,41,1,78, + 41,2,78,78,41,1,78,41,12,114,125,0,0,0,114,124, + 0,0,0,114,126,0,0,0,114,127,0,0,0,114,207,0, + 0,0,114,46,1,0,0,114,52,1,0,0,114,54,1,0, + 0,114,55,1,0,0,114,58,1,0,0,114,203,0,0,0, + 114,206,0,0,0,114,3,0,0,0,114,3,0,0,0,114, + 3,0,0,0,114,6,0,0,0,114,45,1,0,0,204,4, + 0,0,115,30,0,0,0,8,2,4,2,2,1,10,9,2, + 1,10,12,2,1,10,21,2,1,10,14,2,1,12,31,2, + 1,12,23,2,1,114,45,1,0,0,99,0,0,0,0,0, + 0,0,0,0,0,0,0,3,0,0,0,64,0,0,0,115, + 90,0,0,0,101,0,90,1,100,0,90,2,100,1,90,3, + 100,2,100,3,132,0,90,4,100,4,100,5,132,0,90,5, + 101,6,90,7,100,6,100,7,132,0,90,8,100,8,100,9, + 132,0,90,9,100,19,100,11,100,12,132,1,90,10,100,13, + 100,14,132,0,90,11,101,12,100,15,100,16,132,0,131,1, + 90,13,100,17,100,18,132,0,90,14,100,10,83,0,41,20, + 218,10,70,105,108,101,70,105,110,100,101,114,122,172,70,105, + 108,101,45,98,97,115,101,100,32,102,105,110,100,101,114,46, + 10,10,32,32,32,32,73,110,116,101,114,97,99,116,105,111, + 110,115,32,119,105,116,104,32,116,104,101,32,102,105,108,101, + 32,115,121,115,116,101,109,32,97,114,101,32,99,97,99,104, + 101,100,32,102,111,114,32,112,101,114,102,111,114,109,97,110, + 99,101,44,32,98,101,105,110,103,10,32,32,32,32,114,101, + 102,114,101,115,104,101,100,32,119,104,101,110,32,116,104,101, + 32,100,105,114,101,99,116,111,114,121,32,116,104,101,32,102, + 105,110,100,101,114,32,105,115,32,104,97,110,100,108,105,110, + 103,32,104,97,115,32,98,101,101,110,32,109,111,100,105,102, + 105,101,100,46,10,10,32,32,32,32,99,2,0,0,0,0, + 0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,115, + 84,0,0,0,103,0,125,3,124,2,68,0,93,32,92,2, + 137,0,125,4,124,3,160,0,135,0,102,1,100,1,100,2, + 132,8,124,4,68,0,131,1,161,1,1,0,113,8,124,3, + 124,0,95,1,124,1,112,54,100,3,124,0,95,2,100,4, + 124,0,95,3,116,4,131,0,124,0,95,5,116,4,131,0, + 124,0,95,6,100,5,83,0,41,6,122,154,73,110,105,116, + 105,97,108,105,122,101,32,119,105,116,104,32,116,104,101,32, + 112,97,116,104,32,116,111,32,115,101,97,114,99,104,32,111, + 110,32,97,110,100,32,97,32,118,97,114,105,97,98,108,101, + 32,110,117,109,98,101,114,32,111,102,10,32,32,32,32,32, + 32,32,32,50,45,116,117,112,108,101,115,32,99,111,110,116, + 97,105,110,105,110,103,32,116,104,101,32,108,111,97,100,101, + 114,32,97,110,100,32,116,104,101,32,102,105,108,101,32,115, + 117,102,102,105,120,101,115,32,116,104,101,32,108,111,97,100, + 101,114,10,32,32,32,32,32,32,32,32,114,101,99,111,103, + 110,105,122,101,115,46,99,1,0,0,0,0,0,0,0,2, + 0,0,0,3,0,0,0,51,0,0,0,115,22,0,0,0, + 124,0,93,14,125,1,124,1,136,0,102,2,86,0,1,0, + 113,2,100,0,83,0,114,110,0,0,0,114,3,0,0,0, + 114,16,1,0,0,169,1,114,140,0,0,0,114,3,0,0, + 0,114,6,0,0,0,114,19,1,0,0,97,5,0,0,115, + 4,0,0,0,4,0,2,0,122,38,70,105,108,101,70,105, + 110,100,101,114,46,95,95,105,110,105,116,95,95,46,60,108, + 111,99,97,108,115,62,46,60,103,101,110,101,120,112,114,62, + 114,71,0,0,0,114,105,0,0,0,78,41,7,114,167,0, + 0,0,218,8,95,108,111,97,100,101,114,115,114,44,0,0, + 0,218,11,95,112,97,116,104,95,109,116,105,109,101,218,3, + 115,101,116,218,11,95,112,97,116,104,95,99,97,99,104,101, + 218,19,95,114,101,108,97,120,101,100,95,112,97,116,104,95, + 99,97,99,104,101,41,5,114,119,0,0,0,114,44,0,0, + 0,218,14,108,111,97,100,101,114,95,100,101,116,97,105,108, + 115,90,7,108,111,97,100,101,114,115,114,189,0,0,0,114, + 3,0,0,0,114,60,1,0,0,114,6,0,0,0,114,209, + 0,0,0,91,5,0,0,115,16,0,0,0,0,4,4,1, + 12,1,26,1,6,2,10,1,6,1,8,1,122,19,70,105, + 108,101,70,105,110,100,101,114,46,95,95,105,110,105,116,95, + 95,99,1,0,0,0,0,0,0,0,1,0,0,0,2,0, + 0,0,67,0,0,0,115,10,0,0,0,100,1,124,0,95, + 0,100,2,83,0,41,3,122,31,73,110,118,97,108,105,100, + 97,116,101,32,116,104,101,32,100,105,114,101,99,116,111,114, + 121,32,109,116,105,109,101,46,114,105,0,0,0,78,41,1, + 114,62,1,0,0,114,246,0,0,0,114,3,0,0,0,114, + 3,0,0,0,114,6,0,0,0,114,46,1,0,0,105,5, + 0,0,115,2,0,0,0,0,2,122,28,70,105,108,101,70, + 105,110,100,101,114,46,105,110,118,97,108,105,100,97,116,101, + 95,99,97,99,104,101,115,99,2,0,0,0,0,0,0,0, + 3,0,0,0,3,0,0,0,67,0,0,0,115,42,0,0, + 0,124,0,160,0,124,1,161,1,125,2,124,2,100,1,107, + 8,114,26,100,1,103,0,102,2,83,0,124,2,106,1,124, + 2,106,2,112,38,103,0,102,2,83,0,41,2,122,197,84, + 114,121,32,116,111,32,102,105,110,100,32,97,32,108,111,97, + 100,101,114,32,102,111,114,32,116,104,101,32,115,112,101,99, + 105,102,105,101,100,32,109,111,100,117,108,101,44,32,111,114, + 32,116,104,101,32,110,97,109,101,115,112,97,99,101,10,32, + 32,32,32,32,32,32,32,112,97,99,107,97,103,101,32,112, + 111,114,116,105,111,110,115,46,32,82,101,116,117,114,110,115, + 32,40,108,111,97,100,101,114,44,32,108,105,115,116,45,111, + 102,45,112,111,114,116,105,111,110,115,41,46,10,10,32,32, + 32,32,32,32,32,32,84,104,105,115,32,109,101,116,104,111, + 100,32,105,115,32,100,101,112,114,101,99,97,116,101,100,46, + 32,32,85,115,101,32,102,105,110,100,95,115,112,101,99,40, + 41,32,105,110,115,116,101,97,100,46,10,10,32,32,32,32, + 32,32,32,32,78,41,3,114,203,0,0,0,114,140,0,0, + 0,114,178,0,0,0,41,3,114,119,0,0,0,114,139,0, + 0,0,114,187,0,0,0,114,3,0,0,0,114,3,0,0, + 0,114,6,0,0,0,114,137,0,0,0,111,5,0,0,115, + 8,0,0,0,0,7,10,1,8,1,8,1,122,22,70,105, + 108,101,70,105,110,100,101,114,46,102,105,110,100,95,108,111, + 97,100,101,114,99,6,0,0,0,0,0,0,0,7,0,0, + 0,6,0,0,0,67,0,0,0,115,26,0,0,0,124,1, + 124,2,124,3,131,2,125,6,116,0,124,2,124,3,124,6, + 124,4,100,1,141,4,83,0,41,2,78,114,177,0,0,0, + 41,1,114,190,0,0,0,41,7,114,119,0,0,0,114,188, + 0,0,0,114,139,0,0,0,114,44,0,0,0,90,4,115, + 109,115,108,114,202,0,0,0,114,140,0,0,0,114,3,0, + 0,0,114,3,0,0,0,114,6,0,0,0,114,58,1,0, + 0,123,5,0,0,115,8,0,0,0,0,1,10,1,8,1, + 2,255,122,20,70,105,108,101,70,105,110,100,101,114,46,95, + 103,101,116,95,115,112,101,99,78,99,3,0,0,0,0,0, + 0,0,14,0,0,0,8,0,0,0,67,0,0,0,115,102, + 1,0,0,100,1,125,3,124,1,160,0,100,2,161,1,100, + 3,25,0,125,4,122,24,116,1,124,0,106,2,112,34,116, + 3,160,4,161,0,131,1,106,5,125,5,87,0,110,24,4, + 0,116,6,107,10,114,66,1,0,1,0,1,0,100,4,125, + 5,89,0,110,2,88,0,124,5,124,0,106,7,107,3,114, + 92,124,0,160,8,161,0,1,0,124,5,124,0,95,7,116, + 9,131,0,114,114,124,0,106,10,125,6,124,4,160,11,161, + 0,125,7,110,10,124,0,106,12,125,6,124,4,125,7,124, + 7,124,6,107,6,114,218,116,13,124,0,106,2,124,4,131, + 2,125,8,124,0,106,14,68,0,93,58,92,2,125,9,125, + 10,100,5,124,9,23,0,125,11,116,13,124,8,124,11,131, + 2,125,12,116,15,124,12,131,1,114,208,124,0,160,16,124, + 10,124,1,124,12,124,8,103,1,124,2,161,5,2,0,1, + 0,83,0,113,150,116,17,124,8,131,1,125,3,124,0,106, + 14,68,0,93,86,92,2,125,9,125,10,116,13,124,0,106, + 2,124,4,124,9,23,0,131,2,125,12,116,18,106,19,100, + 6,124,12,100,3,100,7,141,3,1,0,124,7,124,9,23, + 0,124,6,107,6,144,1,114,54,116,15,124,12,131,1,144, + 1,114,54,124,0,160,16,124,10,124,1,124,12,100,8,124, + 2,161,5,2,0,1,0,83,0,113,224,124,3,144,1,114, + 98,116,18,160,19,100,9,124,8,161,2,1,0,116,18,160, + 20,124,1,100,8,161,2,125,13,124,8,103,1,124,13,95, + 21,124,13,83,0,100,8,83,0,41,10,122,111,84,114,121, + 32,116,111,32,102,105,110,100,32,97,32,115,112,101,99,32, + 102,111,114,32,116,104,101,32,115,112,101,99,105,102,105,101, + 100,32,109,111,100,117,108,101,46,10,10,32,32,32,32,32, + 32,32,32,82,101,116,117,114,110,115,32,116,104,101,32,109, + 97,116,99,104,105,110,103,32,115,112,101,99,44,32,111,114, + 32,78,111,110,101,32,105,102,32,110,111,116,32,102,111,117, + 110,100,46,10,32,32,32,32,32,32,32,32,70,114,71,0, + 0,0,114,28,0,0,0,114,105,0,0,0,114,209,0,0, + 0,122,9,116,114,121,105,110,103,32,123,125,41,1,90,9, + 118,101,114,98,111,115,105,116,121,78,122,25,112,111,115,115, + 105,98,108,101,32,110,97,109,101,115,112,97,99,101,32,102, + 111,114,32,123,125,41,22,114,41,0,0,0,114,49,0,0, + 0,114,44,0,0,0,114,2,0,0,0,114,55,0,0,0, + 114,9,1,0,0,114,50,0,0,0,114,62,1,0,0,218, + 11,95,102,105,108,108,95,99,97,99,104,101,114,7,0,0, + 0,114,65,1,0,0,114,106,0,0,0,114,64,1,0,0, + 114,38,0,0,0,114,61,1,0,0,114,54,0,0,0,114, + 58,1,0,0,114,56,0,0,0,114,134,0,0,0,114,149, + 0,0,0,114,183,0,0,0,114,178,0,0,0,41,14,114, + 119,0,0,0,114,139,0,0,0,114,202,0,0,0,90,12, + 105,115,95,110,97,109,101,115,112,97,99,101,90,11,116,97, + 105,108,95,109,111,100,117,108,101,114,169,0,0,0,90,5, + 99,97,99,104,101,90,12,99,97,99,104,101,95,109,111,100, + 117,108,101,90,9,98,97,115,101,95,112,97,116,104,114,17, + 1,0,0,114,188,0,0,0,90,13,105,110,105,116,95,102, + 105,108,101,110,97,109,101,90,9,102,117,108,108,95,112,97, + 116,104,114,187,0,0,0,114,3,0,0,0,114,3,0,0, + 0,114,6,0,0,0,114,203,0,0,0,128,5,0,0,115, + 74,0,0,0,0,5,4,1,14,1,2,1,24,1,14,1, + 10,1,10,1,8,1,6,2,6,1,6,1,10,2,6,1, + 4,2,8,1,12,1,14,1,8,1,10,1,8,1,26,4, + 8,2,14,1,16,1,16,1,14,1,10,1,10,1,2,0, + 2,255,10,2,6,1,12,1,12,1,8,1,4,1,122,20, + 70,105,108,101,70,105,110,100,101,114,46,102,105,110,100,95, + 115,112,101,99,99,1,0,0,0,0,0,0,0,9,0,0, + 0,10,0,0,0,67,0,0,0,115,190,0,0,0,124,0, + 106,0,125,1,122,22,116,1,160,2,124,1,112,22,116,1, + 160,3,161,0,161,1,125,2,87,0,110,30,4,0,116,4, + 116,5,116,6,102,3,107,10,114,58,1,0,1,0,1,0, + 103,0,125,2,89,0,110,2,88,0,116,7,106,8,160,9, + 100,1,161,1,115,84,116,10,124,2,131,1,124,0,95,11, + 110,74,116,10,131,0,125,3,124,2,68,0,93,56,125,4, + 124,4,160,12,100,2,161,1,92,3,125,5,125,6,125,7, + 124,6,114,136,100,3,160,13,124,5,124,7,160,14,161,0, + 161,2,125,8,110,4,124,5,125,8,124,3,160,15,124,8, + 161,1,1,0,113,94,124,3,124,0,95,11,116,7,106,8, + 160,9,116,16,161,1,114,186,100,4,100,5,132,0,124,2, + 68,0,131,1,124,0,95,17,100,6,83,0,41,7,122,68, + 70,105,108,108,32,116,104,101,32,99,97,99,104,101,32,111, + 102,32,112,111,116,101,110,116,105,97,108,32,109,111,100,117, + 108,101,115,32,97,110,100,32,112,97,99,107,97,103,101,115, + 32,102,111,114,32,116,104,105,115,32,100,105,114,101,99,116, + 111,114,121,46,114,0,0,0,0,114,71,0,0,0,114,61, + 0,0,0,99,1,0,0,0,0,0,0,0,2,0,0,0, + 4,0,0,0,83,0,0,0,115,20,0,0,0,104,0,124, + 0,93,12,125,1,124,1,160,0,161,0,146,2,113,4,83, + 0,114,3,0,0,0,41,1,114,106,0,0,0,41,2,114, + 32,0,0,0,90,2,102,110,114,3,0,0,0,114,3,0, + 0,0,114,6,0,0,0,218,9,60,115,101,116,99,111,109, + 112,62,205,5,0,0,115,4,0,0,0,6,0,2,0,122, + 41,70,105,108,101,70,105,110,100,101,114,46,95,102,105,108, + 108,95,99,97,99,104,101,46,60,108,111,99,97,108,115,62, + 46,60,115,101,116,99,111,109,112,62,78,41,18,114,44,0, + 0,0,114,2,0,0,0,114,6,1,0,0,114,55,0,0, + 0,114,2,1,0,0,218,15,80,101,114,109,105,115,115,105, + 111,110,69,114,114,111,114,218,18,78,111,116,65,68,105,114, + 101,99,116,111,114,121,69,114,114,111,114,114,8,0,0,0, + 114,9,0,0,0,114,10,0,0,0,114,63,1,0,0,114, + 64,1,0,0,114,101,0,0,0,114,62,0,0,0,114,106, + 0,0,0,218,3,97,100,100,114,11,0,0,0,114,65,1, + 0,0,41,9,114,119,0,0,0,114,44,0,0,0,114,7, + 1,0,0,90,21,108,111,119,101,114,95,115,117,102,102,105, + 120,95,99,111,110,116,101,110,116,115,114,41,1,0,0,114, + 117,0,0,0,114,29,1,0,0,114,17,1,0,0,90,8, + 110,101,119,95,110,97,109,101,114,3,0,0,0,114,3,0, + 0,0,114,6,0,0,0,114,67,1,0,0,176,5,0,0, + 115,34,0,0,0,0,2,6,1,2,1,22,1,20,3,10, + 3,12,1,12,7,6,1,8,1,16,1,4,1,18,2,4, + 1,12,1,6,1,12,1,122,22,70,105,108,101,70,105,110, + 100,101,114,46,95,102,105,108,108,95,99,97,99,104,101,99, + 1,0,0,0,0,0,0,0,3,0,0,0,3,0,0,0, + 7,0,0,0,115,18,0,0,0,135,0,135,1,102,2,100, + 1,100,2,132,8,125,2,124,2,83,0,41,3,97,20,1, + 0,0,65,32,99,108,97,115,115,32,109,101,116,104,111,100, + 32,119,104,105,99,104,32,114,101,116,117,114,110,115,32,97, + 32,99,108,111,115,117,114,101,32,116,111,32,117,115,101,32, + 111,110,32,115,121,115,46,112,97,116,104,95,104,111,111,107, + 10,32,32,32,32,32,32,32,32,119,104,105,99,104,32,119, + 105,108,108,32,114,101,116,117,114,110,32,97,110,32,105,110, + 115,116,97,110,99,101,32,117,115,105,110,103,32,116,104,101, + 32,115,112,101,99,105,102,105,101,100,32,108,111,97,100,101, + 114,115,32,97,110,100,32,116,104,101,32,112,97,116,104,10, + 32,32,32,32,32,32,32,32,99,97,108,108,101,100,32,111, + 110,32,116,104,101,32,99,108,111,115,117,114,101,46,10,10, + 32,32,32,32,32,32,32,32,73,102,32,116,104,101,32,112, + 97,116,104,32,99,97,108,108,101,100,32,111,110,32,116,104, + 101,32,99,108,111,115,117,114,101,32,105,115,32,110,111,116, + 32,97,32,100,105,114,101,99,116,111,114,121,44,32,73,109, + 112,111,114,116,69,114,114,111,114,32,105,115,10,32,32,32, + 32,32,32,32,32,114,97,105,115,101,100,46,10,10,32,32, + 32,32,32,32,32,32,99,1,0,0,0,0,0,0,0,1, + 0,0,0,4,0,0,0,19,0,0,0,115,34,0,0,0, + 116,0,124,0,131,1,115,20,116,1,100,1,124,0,100,2, + 141,2,130,1,136,0,124,0,102,1,136,1,158,2,142,0, + 83,0,41,3,122,45,80,97,116,104,32,104,111,111,107,32, + 102,111,114,32,105,109,112,111,114,116,108,105,98,46,109,97, + 99,104,105,110,101,114,121,46,70,105,108,101,70,105,110,100, + 101,114,46,122,30,111,110,108,121,32,100,105,114,101,99,116, + 111,114,105,101,115,32,97,114,101,32,115,117,112,112,111,114, + 116,101,100,114,48,0,0,0,41,2,114,56,0,0,0,114, + 118,0,0,0,114,48,0,0,0,169,2,114,193,0,0,0, + 114,66,1,0,0,114,3,0,0,0,114,6,0,0,0,218, + 24,112,97,116,104,95,104,111,111,107,95,102,111,114,95,70, + 105,108,101,70,105,110,100,101,114,217,5,0,0,115,6,0, + 0,0,0,2,8,1,12,1,122,54,70,105,108,101,70,105, + 110,100,101,114,46,112,97,116,104,95,104,111,111,107,46,60, + 108,111,99,97,108,115,62,46,112,97,116,104,95,104,111,111, + 107,95,102,111,114,95,70,105,108,101,70,105,110,100,101,114, + 114,3,0,0,0,41,3,114,193,0,0,0,114,66,1,0, + 0,114,73,1,0,0,114,3,0,0,0,114,72,1,0,0, + 114,6,0,0,0,218,9,112,97,116,104,95,104,111,111,107, + 207,5,0,0,115,4,0,0,0,0,10,14,6,122,20,70, + 105,108,101,70,105,110,100,101,114,46,112,97,116,104,95,104, + 111,111,107,99,1,0,0,0,0,0,0,0,1,0,0,0, + 3,0,0,0,67,0,0,0,115,12,0,0,0,100,1,160, + 0,124,0,106,1,161,1,83,0,41,2,78,122,16,70,105, + 108,101,70,105,110,100,101,114,40,123,33,114,125,41,41,2, + 114,62,0,0,0,114,44,0,0,0,114,246,0,0,0,114, + 3,0,0,0,114,3,0,0,0,114,6,0,0,0,114,39, + 1,0,0,225,5,0,0,115,2,0,0,0,0,1,122,19, + 70,105,108,101,70,105,110,100,101,114,46,95,95,114,101,112, + 114,95,95,41,1,78,41,15,114,125,0,0,0,114,124,0, + 0,0,114,126,0,0,0,114,127,0,0,0,114,209,0,0, + 0,114,46,1,0,0,114,143,0,0,0,114,206,0,0,0, + 114,137,0,0,0,114,58,1,0,0,114,203,0,0,0,114, + 67,1,0,0,114,207,0,0,0,114,74,1,0,0,114,39, + 1,0,0,114,3,0,0,0,114,3,0,0,0,114,3,0, + 0,0,114,6,0,0,0,114,59,1,0,0,82,5,0,0, + 115,22,0,0,0,8,2,4,7,8,14,8,4,4,2,8, + 12,8,5,10,48,8,31,2,1,10,17,114,59,1,0,0, + 99,4,0,0,0,0,0,0,0,6,0,0,0,8,0,0, + 0,67,0,0,0,115,146,0,0,0,124,0,160,0,100,1, + 161,1,125,4,124,0,160,0,100,2,161,1,125,5,124,4, + 115,66,124,5,114,36,124,5,106,1,125,4,110,30,124,2, + 124,3,107,2,114,56,116,2,124,1,124,2,131,2,125,4, + 110,10,116,3,124,1,124,2,131,2,125,4,124,5,115,84, + 116,4,124,1,124,2,124,4,100,3,141,3,125,5,122,36, + 124,5,124,0,100,2,60,0,124,4,124,0,100,1,60,0, + 124,2,124,0,100,4,60,0,124,3,124,0,100,5,60,0, + 87,0,110,20,4,0,116,5,107,10,114,140,1,0,1,0, + 1,0,89,0,110,2,88,0,100,0,83,0,41,6,78,218, + 10,95,95,108,111,97,100,101,114,95,95,218,8,95,95,115, + 112,101,99,95,95,114,60,1,0,0,90,8,95,95,102,105, + 108,101,95,95,90,10,95,95,99,97,99,104,101,100,95,95, + 41,6,218,3,103,101,116,114,140,0,0,0,114,14,1,0, + 0,114,8,1,0,0,114,190,0,0,0,218,9,69,120,99, + 101,112,116,105,111,110,41,6,90,2,110,115,114,117,0,0, + 0,90,8,112,97,116,104,110,97,109,101,90,9,99,112,97, + 116,104,110,97,109,101,114,140,0,0,0,114,187,0,0,0, + 114,3,0,0,0,114,3,0,0,0,114,6,0,0,0,218, + 14,95,102,105,120,95,117,112,95,109,111,100,117,108,101,231, + 5,0,0,115,34,0,0,0,0,2,10,1,10,1,4,1, + 4,1,8,1,8,1,12,2,10,1,4,1,14,1,2,1, + 8,1,8,1,8,1,12,1,14,2,114,79,1,0,0,99, + 0,0,0,0,0,0,0,0,3,0,0,0,3,0,0,0, + 67,0,0,0,115,38,0,0,0,116,0,116,1,160,2,161, + 0,102,2,125,0,116,3,116,4,102,2,125,1,116,5,116, + 6,102,2,125,2,124,0,124,1,124,2,103,3,83,0,41, + 1,122,95,82,101,116,117,114,110,115,32,97,32,108,105,115, + 116,32,111,102,32,102,105,108,101,45,98,97,115,101,100,32, + 109,111,100,117,108,101,32,108,111,97,100,101,114,115,46,10, + 10,32,32,32,32,69,97,99,104,32,105,116,101,109,32,105, + 115,32,97,32,116,117,112,108,101,32,40,108,111,97,100,101, + 114,44,32,115,117,102,102,105,120,101,115,41,46,10,32,32, + 32,32,41,7,114,15,1,0,0,114,163,0,0,0,218,18, + 101,120,116,101,110,115,105,111,110,95,115,117,102,102,105,120, + 101,115,114,8,1,0,0,114,102,0,0,0,114,14,1,0, + 0,114,89,0,0,0,41,3,90,10,101,120,116,101,110,115, + 105,111,110,115,90,6,115,111,117,114,99,101,90,8,98,121, + 116,101,99,111,100,101,114,3,0,0,0,114,3,0,0,0, + 114,6,0,0,0,114,184,0,0,0,254,5,0,0,115,8, + 0,0,0,0,5,12,1,8,1,8,1,114,184,0,0,0, + 99,1,0,0,0,0,0,0,0,12,0,0,0,9,0,0, + 0,67,0,0,0,115,178,1,0,0,124,0,97,0,116,0, + 106,1,97,1,116,0,106,2,97,2,116,1,106,3,116,4, + 25,0,125,1,100,1,68,0,93,48,125,2,124,2,116,1, + 106,3,107,7,114,56,116,0,160,5,124,2,161,1,125,3, + 110,10,116,1,106,3,124,2,25,0,125,3,116,6,124,1, + 124,2,124,3,131,3,1,0,113,30,100,2,100,3,103,1, + 102,2,100,4,100,5,100,3,103,2,102,2,102,2,125,4, + 124,4,68,0,93,110,92,2,125,5,125,6,116,7,100,6, + 100,7,132,0,124,6,68,0,131,1,131,1,115,136,116,8, + 130,1,124,6,100,8,25,0,125,7,124,5,116,1,106,3, + 107,6,114,170,116,1,106,3,124,5,25,0,125,8,1,0, + 113,226,113,106,122,20,116,0,160,5,124,5,161,1,125,8, + 87,0,1,0,113,226,87,0,113,106,4,0,116,9,107,10, + 114,214,1,0,1,0,1,0,89,0,113,106,89,0,113,106, + 88,0,113,106,116,9,100,9,131,1,130,1,116,6,124,1, + 100,10,124,8,131,3,1,0,116,6,124,1,100,11,124,7, + 131,3,1,0,116,6,124,1,100,12,100,13,160,10,124,6, + 161,1,131,3,1,0,116,6,124,1,100,14,100,15,100,16, + 132,0,124,6,68,0,131,1,131,3,1,0,116,0,160,5, + 100,17,161,1,125,9,116,6,124,1,100,17,124,9,131,3, + 1,0,116,0,160,5,100,18,161,1,125,10,116,6,124,1, + 100,18,124,10,131,3,1,0,124,5,100,4,107,2,144,1, + 114,110,116,0,160,5,100,19,161,1,125,11,116,6,124,1, + 100,20,124,11,131,3,1,0,116,6,124,1,100,21,116,11, + 131,0,131,3,1,0,116,12,160,13,116,2,160,14,161,0, + 161,1,1,0,124,5,100,4,107,2,144,1,114,174,116,15, + 160,16,100,22,161,1,1,0,100,23,116,12,107,6,144,1, + 114,174,100,24,116,17,95,18,100,25,83,0,41,26,122,205, + 83,101,116,117,112,32,116,104,101,32,112,97,116,104,45,98, + 97,115,101,100,32,105,109,112,111,114,116,101,114,115,32,102, + 111,114,32,105,109,112,111,114,116,108,105,98,32,98,121,32, + 105,109,112,111,114,116,105,110,103,32,110,101,101,100,101,100, + 10,32,32,32,32,98,117,105,108,116,45,105,110,32,109,111, + 100,117,108,101,115,32,97,110,100,32,105,110,106,101,99,116, + 105,110,103,32,116,104,101,109,32,105,110,116,111,32,116,104, + 101,32,103,108,111,98,97,108,32,110,97,109,101,115,112,97, + 99,101,46,10,10,32,32,32,32,79,116,104,101,114,32,99, + 111,109,112,111,110,101,110,116,115,32,97,114,101,32,101,120, + 116,114,97,99,116,101,100,32,102,114,111,109,32,116,104,101, + 32,99,111,114,101,32,98,111,111,116,115,116,114,97,112,32, + 109,111,100,117,108,101,46,10,10,32,32,32,32,41,4,114, + 64,0,0,0,114,75,0,0,0,218,8,98,117,105,108,116, + 105,110,115,114,160,0,0,0,90,5,112,111,115,105,120,250, + 1,47,90,2,110,116,250,1,92,99,1,0,0,0,0,0, + 0,0,2,0,0,0,3,0,0,0,115,0,0,0,115,26, + 0,0,0,124,0,93,18,125,1,116,0,124,1,131,1,100, + 0,107,2,86,0,1,0,113,2,100,1,83,0,41,2,114, + 39,0,0,0,78,41,1,114,22,0,0,0,41,2,114,32, + 0,0,0,114,95,0,0,0,114,3,0,0,0,114,3,0, + 0,0,114,6,0,0,0,114,19,1,0,0,34,6,0,0, + 115,4,0,0,0,4,0,2,0,122,25,95,115,101,116,117, + 112,46,60,108,111,99,97,108,115,62,46,60,103,101,110,101, + 120,112,114,62,114,73,0,0,0,122,30,105,109,112,111,114, + 116,108,105,98,32,114,101,113,117,105,114,101,115,32,112,111, + 115,105,120,32,111,114,32,110,116,114,2,0,0,0,114,35, + 0,0,0,114,31,0,0,0,114,40,0,0,0,114,58,0, + 0,0,99,1,0,0,0,0,0,0,0,2,0,0,0,4, + 0,0,0,83,0,0,0,115,22,0,0,0,104,0,124,0, + 93,14,125,1,100,0,124,1,155,0,157,2,146,2,113,4, + 83,0,41,1,114,74,0,0,0,114,3,0,0,0,41,2, + 114,32,0,0,0,218,1,115,114,3,0,0,0,114,3,0, + 0,0,114,6,0,0,0,114,68,1,0,0,50,6,0,0, + 115,4,0,0,0,6,0,2,0,122,25,95,115,101,116,117, + 112,46,60,108,111,99,97,108,115,62,46,60,115,101,116,99, + 111,109,112,62,90,7,95,116,104,114,101,97,100,90,8,95, + 119,101,97,107,114,101,102,90,6,119,105,110,114,101,103,114, + 192,0,0,0,114,7,0,0,0,122,4,46,112,121,119,122, + 6,95,100,46,112,121,100,84,78,41,19,114,134,0,0,0, + 114,8,0,0,0,114,163,0,0,0,114,31,1,0,0,114, + 125,0,0,0,90,18,95,98,117,105,108,116,105,110,95,102, + 114,111,109,95,110,97,109,101,114,129,0,0,0,218,3,97, + 108,108,114,23,0,0,0,114,118,0,0,0,114,36,0,0, + 0,114,13,0,0,0,114,21,1,0,0,114,167,0,0,0, + 114,80,1,0,0,114,102,0,0,0,114,186,0,0,0,114, + 191,0,0,0,114,195,0,0,0,41,12,218,17,95,98,111, + 111,116,115,116,114,97,112,95,109,111,100,117,108,101,90,11, + 115,101,108,102,95,109,111,100,117,108,101,90,12,98,117,105, + 108,116,105,110,95,110,97,109,101,90,14,98,117,105,108,116, + 105,110,95,109,111,100,117,108,101,90,10,111,115,95,100,101, + 116,97,105,108,115,90,10,98,117,105,108,116,105,110,95,111, + 115,114,31,0,0,0,114,35,0,0,0,90,9,111,115,95, + 109,111,100,117,108,101,90,13,116,104,114,101,97,100,95,109, + 111,100,117,108,101,90,14,119,101,97,107,114,101,102,95,109, + 111,100,117,108,101,90,13,119,105,110,114,101,103,95,109,111, + 100,117,108,101,114,3,0,0,0,114,3,0,0,0,114,6, + 0,0,0,218,6,95,115,101,116,117,112,9,6,0,0,115, + 78,0,0,0,0,8,4,1,6,1,6,3,10,1,8,1, + 10,1,12,2,10,1,14,3,22,1,12,2,22,1,8,1, + 10,1,10,1,6,2,2,1,10,1,10,1,14,1,12,2, + 8,1,12,1,12,1,18,1,22,3,10,1,12,3,10,1, + 12,3,10,1,10,1,12,3,14,1,14,1,10,1,10,1, + 10,1,114,87,1,0,0,99,1,0,0,0,0,0,0,0, + 2,0,0,0,4,0,0,0,67,0,0,0,115,50,0,0, + 0,116,0,124,0,131,1,1,0,116,1,131,0,125,1,116, + 2,106,3,160,4,116,5,106,6,124,1,142,0,103,1,161, + 1,1,0,116,2,106,7,160,8,116,9,161,1,1,0,100, + 1,83,0,41,2,122,41,73,110,115,116,97,108,108,32,116, + 104,101,32,112,97,116,104,45,98,97,115,101,100,32,105,109, + 112,111,114,116,32,99,111,109,112,111,110,101,110,116,115,46, + 78,41,10,114,87,1,0,0,114,184,0,0,0,114,8,0, + 0,0,114,51,1,0,0,114,167,0,0,0,114,59,1,0, + 0,114,74,1,0,0,218,9,109,101,116,97,95,112,97,116, + 104,114,186,0,0,0,114,45,1,0,0,41,2,114,86,1, + 0,0,90,17,115,117,112,112,111,114,116,101,100,95,108,111, + 97,100,101,114,115,114,3,0,0,0,114,3,0,0,0,114, + 6,0,0,0,218,8,95,105,110,115,116,97,108,108,74,6, + 0,0,115,8,0,0,0,0,2,8,1,6,1,20,1,114, + 89,1,0,0,41,63,114,127,0,0,0,114,12,0,0,0, + 90,37,95,67,65,83,69,95,73,78,83,69,78,83,73,84, + 73,86,69,95,80,76,65,84,70,79,82,77,83,95,66,89, + 84,69,83,95,75,69,89,114,11,0,0,0,114,13,0,0, + 0,114,20,0,0,0,114,27,0,0,0,114,29,0,0,0, + 114,38,0,0,0,114,47,0,0,0,114,49,0,0,0,114, + 53,0,0,0,114,54,0,0,0,114,56,0,0,0,114,59, + 0,0,0,114,69,0,0,0,218,4,116,121,112,101,218,8, + 95,95,99,111,100,101,95,95,114,162,0,0,0,114,18,0, + 0,0,114,148,0,0,0,114,17,0,0,0,114,24,0,0, + 0,114,236,0,0,0,114,92,0,0,0,114,88,0,0,0, + 114,102,0,0,0,114,89,0,0,0,90,23,68,69,66,85, + 71,95,66,89,84,69,67,79,68,69,95,83,85,70,70,73, + 88,69,83,90,27,79,80,84,73,77,73,90,69,68,95,66, + 89,84,69,67,79,68,69,95,83,85,70,70,73,88,69,83, + 114,98,0,0,0,114,103,0,0,0,114,109,0,0,0,114, + 113,0,0,0,114,115,0,0,0,114,136,0,0,0,114,143, + 0,0,0,114,152,0,0,0,114,156,0,0,0,114,158,0, + 0,0,114,165,0,0,0,114,170,0,0,0,114,171,0,0, + 0,114,176,0,0,0,218,6,111,98,106,101,99,116,114,185, + 0,0,0,114,190,0,0,0,114,191,0,0,0,114,208,0, + 0,0,114,221,0,0,0,114,239,0,0,0,114,8,1,0, + 0,114,14,1,0,0,114,21,1,0,0,114,15,1,0,0, + 114,22,1,0,0,114,43,1,0,0,114,45,1,0,0,114, + 59,1,0,0,114,79,1,0,0,114,184,0,0,0,114,87, + 1,0,0,114,89,1,0,0,114,3,0,0,0,114,3,0, + 0,0,114,3,0,0,0,114,6,0,0,0,218,8,60,109, + 111,100,117,108,101,62,1,0,0,0,115,126,0,0,0,4, + 22,4,1,4,1,2,1,2,255,4,4,8,17,8,5,8, + 5,8,6,8,6,8,12,8,10,8,9,8,5,8,7,8, + 9,12,22,10,127,0,7,16,1,12,2,4,1,4,2,6, + 2,6,2,8,2,18,71,8,40,8,19,8,12,8,12,8, + 28,8,17,8,33,8,28,8,24,16,13,14,10,12,11,8, + 14,6,3,6,1,2,255,12,68,14,64,14,29,16,127,0, + 17,14,68,18,45,18,26,4,3,18,53,14,63,14,42,14, + 127,0,7,14,127,0,22,12,23,8,11,8,65, }; -- cgit v1.2.1 From 7bda9de5504382931822baecba7f85028031c2cd Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 8 Mar 2019 17:25:54 -0700 Subject: Simplify DISPATCH by hoisting eval_breaker ahead of time. (gh-12243) --- Python/ceval.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index b311248c6a..ab6a5e0f12 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -602,6 +602,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject **fastlocals, **freevars; PyObject *retval = NULL; /* Return value */ PyThreadState *tstate = _PyThreadState_GET(); + _Py_atomic_int *eval_breaker = &_PyRuntime.ceval.eval_breaker; PyCodeObject *co; /* when tracing we set things up so that @@ -687,7 +688,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) #define DISPATCH() \ { \ - if (!_Py_atomic_load_relaxed(&_PyRuntime.ceval.eval_breaker)) { \ + if (!_Py_atomic_load_relaxed(eval_breaker)) { \ FAST_DISPATCH(); \ } \ continue; \ @@ -989,7 +990,7 @@ main_loop: async I/O handler); see Py_AddPendingCall() and Py_MakePendingCalls() above. */ - if (_Py_atomic_load_relaxed(&_PyRuntime.ceval.eval_breaker)) { + if (_Py_atomic_load_relaxed(eval_breaker)) { opcode = _Py_OPCODE(*next_instr); if (opcode == SETUP_FINALLY || opcode == SETUP_WITH || -- cgit v1.2.1 From 5be45a6105d656c551adeee7770afdc3b806fbb5 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 8 Mar 2019 22:47:07 -0700 Subject: bpo-33608: Minor cleanup related to pending calls. (gh-12247) --- Python/ceval.c | 80 +++++++++++++++++++++++++++++++--------------------- Python/pylifecycle.c | 1 + Python/pystate.c | 63 ++++++++++++++++++----------------------- 3 files changed, 77 insertions(+), 67 deletions(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index ab6a5e0f12..356335a7c3 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -174,9 +174,11 @@ PyEval_InitThreads(void) PyThread_init_thread(); create_gil(); take_gil(_PyThreadState_GET()); - _PyRuntime.ceval.pending.main_thread = PyThread_get_thread_ident(); - if (!_PyRuntime.ceval.pending.lock) + // Set it to the ID of the main thread of the main interpreter. + _PyRuntime.main_thread = PyThread_get_thread_ident(); + if (!_PyRuntime.ceval.pending.lock) { _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); + } } void @@ -243,9 +245,9 @@ PyEval_ReInitThreads(void) if (!gil_created()) return; recreate_gil(); - _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); take_gil(current_tstate); - _PyRuntime.ceval.pending.main_thread = PyThread_get_thread_ident(); + _PyRuntime.main_thread = PyThread_get_thread_ident(); + _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); /* Destroy all threads except the current one */ _PyThreadState_DeleteExcept(current_tstate); @@ -323,6 +325,35 @@ _PyEval_SignalReceived(void) SIGNAL_PENDING_SIGNALS(); } +/* Push one item onto the queue while holding the lock. */ +static int +_push_pending_call(int (*func)(void *), void *arg) +{ + int i = _PyRuntime.ceval.pending.last; + int j = (i + 1) % NPENDINGCALLS; + if (j == _PyRuntime.ceval.pending.first) { + return -1; /* Queue full */ + } + _PyRuntime.ceval.pending.calls[i].func = func; + _PyRuntime.ceval.pending.calls[i].arg = arg; + _PyRuntime.ceval.pending.last = j; + return 0; +} + +/* Pop one item off the queue while holding the lock. */ +static void +_pop_pending_call(int (**func)(void *), void **arg) +{ + int i = _PyRuntime.ceval.pending.first; + if (i == _PyRuntime.ceval.pending.last) { + return; /* Queue empty */ + } + + *func = _PyRuntime.ceval.pending.calls[i].func; + *arg = _PyRuntime.ceval.pending.calls[i].arg; + _PyRuntime.ceval.pending.first = (i + 1) % NPENDINGCALLS; +} + /* This implementation is thread-safe. It allows scheduling to be made from any thread, and even from an executing callback. @@ -331,7 +362,6 @@ _PyEval_SignalReceived(void) int Py_AddPendingCall(int (*func)(void *), void *arg) { - int i, j, result=0; PyThread_type_lock lock = _PyRuntime.ceval.pending.lock; /* try a few times for the lock. Since this mechanism is used @@ -346,6 +376,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg) * this function is called before any bytecode evaluation takes place. */ if (lock != NULL) { + int i; for (i = 0; i<100; i++) { if (PyThread_acquire_lock(lock, NOWAIT_LOCK)) break; @@ -354,15 +385,8 @@ Py_AddPendingCall(int (*func)(void *), void *arg) return -1; } - i = _PyRuntime.ceval.pending.last; - j = (i + 1) % NPENDINGCALLS; - if (j == _PyRuntime.ceval.pending.first) { - result = -1; /* Queue full */ - } else { - _PyRuntime.ceval.pending.calls[i].func = func; - _PyRuntime.ceval.pending.calls[i].arg = arg; - _PyRuntime.ceval.pending.last = j; - } + int result = _push_pending_call(func, arg); + /* signal main loop */ SIGNAL_PENDING_CALLS(); if (lock != NULL) @@ -373,10 +397,10 @@ Py_AddPendingCall(int (*func)(void *), void *arg) static int handle_signals(void) { - /* Only handle signals on main thread. */ - if (_PyRuntime.ceval.pending.main_thread && - PyThread_get_thread_ident() != _PyRuntime.ceval.pending.main_thread) - { + /* Only handle signals on main thread. PyEval_InitThreads must + * have been called already. + */ + if (PyThread_get_thread_ident() != _PyRuntime.main_thread) { return 0; } /* @@ -401,9 +425,7 @@ make_pending_calls(void) static int busy = 0; /* only service pending calls on main thread */ - if (_PyRuntime.ceval.pending.main_thread && - PyThread_get_thread_ident() != _PyRuntime.ceval.pending.main_thread) - { + if (PyThread_get_thread_ident() != _PyRuntime.main_thread) { return 0; } @@ -428,24 +450,18 @@ make_pending_calls(void) /* perform a bounded number of calls, in case of recursion */ for (int i=0; iframe != NULL) Py_FatalError("Py_EndInterpreter: thread still has a frame"); + interp->finalizing = 1; wait_for_thread_shutdown(); diff --git a/Python/pystate.c b/Python/pystate.c index 49497b7c37..ec8dba8ee5 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -60,6 +60,8 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime) return _Py_INIT_ERR("Can't initialize threads for cross-interpreter data registry"); } + // runtime->main_thread is set in PyEval_InitThreads(). + return _Py_INIT_OK(); } @@ -133,28 +135,12 @@ PyInterpreterState_New(void) return NULL; } + memset(interp, 0, sizeof(*interp)); interp->id_refcount = -1; - interp->id_mutex = NULL; - interp->modules = NULL; - interp->modules_by_index = NULL; - interp->sysdict = NULL; - interp->builtins = NULL; - interp->builtins_copy = NULL; - interp->tstate_head = NULL; interp->check_interval = 100; - interp->num_threads = 0; - interp->pythread_stacksize = 0; - interp->codec_search_path = NULL; - interp->codec_search_cache = NULL; - interp->codec_error_registry = NULL; - interp->codecs_initialized = 0; - interp->fscodec_initialized = 0; interp->core_config = _PyCoreConfig_INIT; interp->config = _PyMainInterpreterConfig_INIT; - interp->importlib = NULL; - interp->import_func = NULL; interp->eval_frame = _PyEval_EvalFrameDefault; - interp->co_extra_user_count = 0; #ifdef HAVE_DLOPEN #if HAVE_DECL_RTLD_NOW interp->dlopenflags = RTLD_NOW; @@ -162,13 +148,6 @@ PyInterpreterState_New(void) interp->dlopenflags = RTLD_LAZY; #endif #endif -#ifdef HAVE_FORK - interp->before_forkers = NULL; - interp->after_forkers_parent = NULL; - interp->after_forkers_child = NULL; -#endif - interp->pyexitfunc = NULL; - interp->pyexitmodule = NULL; HEAD_LOCK(); if (_PyRuntime.interpreters.next_id < 0) { @@ -223,6 +202,9 @@ PyInterpreterState_Clear(PyInterpreterState *interp) Py_CLEAR(interp->after_forkers_parent); Py_CLEAR(interp->after_forkers_child); #endif + // XXX Once we have one allocator per interpreter (i.e. + // per-interpreter GC) we must ensure that all of the interpreter's + // objects have been cleaned up at the point. } @@ -334,28 +316,39 @@ PyInterpreterState_GetID(PyInterpreterState *interp) } -PyInterpreterState * -_PyInterpreterState_LookUpID(PY_INT64_T requested_id) +static PyInterpreterState * +interp_look_up_id(PY_INT64_T requested_id) { - if (requested_id < 0) - goto error; - PyInterpreterState *interp = PyInterpreterState_Head(); while (interp != NULL) { PY_INT64_T id = PyInterpreterState_GetID(interp); - if (id < 0) + if (id < 0) { return NULL; - if (requested_id == id) + } + if (requested_id == id) { return interp; + } interp = PyInterpreterState_Next(interp); } - -error: - PyErr_Format(PyExc_RuntimeError, - "unrecognized interpreter ID %lld", requested_id); return NULL; } +PyInterpreterState * +_PyInterpreterState_LookUpID(PY_INT64_T requested_id) +{ + PyInterpreterState *interp = NULL; + if (requested_id >= 0) { + HEAD_LOCK(); + interp = interp_look_up_id(requested_id); + HEAD_UNLOCK(); + } + if (interp == NULL && !PyErr_Occurred()) { + PyErr_Format(PyExc_RuntimeError, + "unrecognized interpreter ID %lld", requested_id); + } + return interp; +} + int _PyInterpreterState_IDInitref(PyInterpreterState *interp) -- cgit v1.2.1 From 8479a3426eb7d1840473f7788e639954363ed37e Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 8 Mar 2019 23:44:33 -0700 Subject: bpo-33608: Make sure locks in the runtime are properly re-created. (gh-12245) --- Python/ceval.c | 49 ++++++++++--------------------------------------- Python/pystate.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 40 deletions(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index 356335a7c3..373cde9a17 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -174,10 +174,10 @@ PyEval_InitThreads(void) PyThread_init_thread(); create_gil(); take_gil(_PyThreadState_GET()); - // Set it to the ID of the main thread of the main interpreter. - _PyRuntime.main_thread = PyThread_get_thread_ident(); - if (!_PyRuntime.ceval.pending.lock) { - _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); + + _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); + if (_PyRuntime.ceval.pending.lock == NULL) { + return Py_FatalError("Can't initialize threads for pending calls"); } } @@ -246,8 +246,11 @@ PyEval_ReInitThreads(void) return; recreate_gil(); take_gil(current_tstate); - _PyRuntime.main_thread = PyThread_get_thread_ident(); + _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); + if (_PyRuntime.ceval.pending.lock == NULL) { + Py_FatalError("Can't initialize threads for pending calls"); + } /* Destroy all threads except the current one */ _PyThreadState_DeleteExcept(current_tstate); @@ -362,35 +365,12 @@ _pop_pending_call(int (**func)(void *), void **arg) int Py_AddPendingCall(int (*func)(void *), void *arg) { - PyThread_type_lock lock = _PyRuntime.ceval.pending.lock; - - /* try a few times for the lock. Since this mechanism is used - * for signal handling (on the main thread), there is a (slim) - * chance that a signal is delivered on the same thread while we - * hold the lock during the Py_MakePendingCalls() function. - * This avoids a deadlock in that case. - * Note that signals can be delivered on any thread. In particular, - * on Windows, a SIGINT is delivered on a system-created worker - * thread. - * We also check for lock being NULL, in the unlikely case that - * this function is called before any bytecode evaluation takes place. - */ - if (lock != NULL) { - int i; - for (i = 0; i<100; i++) { - if (PyThread_acquire_lock(lock, NOWAIT_LOCK)) - break; - } - if (i == 100) - return -1; - } - + PyThread_acquire_lock(_PyRuntime.ceval.pending.lock, WAIT_LOCK); int result = _push_pending_call(func, arg); + PyThread_release_lock(_PyRuntime.ceval.pending.lock); /* signal main loop */ SIGNAL_PENDING_CALLS(); - if (lock != NULL) - PyThread_release_lock(lock); return result; } @@ -439,15 +419,6 @@ make_pending_calls(void) UNSIGNAL_PENDING_CALLS(); int res = 0; - if (!_PyRuntime.ceval.pending.lock) { - /* initial allocation of the lock */ - _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); - if (_PyRuntime.ceval.pending.lock == NULL) { - res = -1; - goto error; - } - } - /* perform a bounded number of calls, in case of recursion */ for (int i=0; imain_thread is set in PyEval_InitThreads(). + // Set it to the ID of the main thread of the main interpreter. + runtime->main_thread = PyThread_get_thread_ident(); return _Py_INIT_OK(); } @@ -94,6 +95,32 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime) PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } +/* This function is called from PyOS_AfterFork_Child to ensure that + * newly created child processes do not share locks with the parent. + */ + +void +_PyRuntimeState_ReInitThreads(void) +{ + // This was initially set in _PyRuntimeState_Init(). + _PyRuntime.main_thread = PyThread_get_thread_ident(); + + _PyRuntime.interpreters.mutex = PyThread_allocate_lock(); + if (_PyRuntime.interpreters.mutex == NULL) { + Py_FatalError("Can't initialize lock for runtime interpreters"); + } + + _PyRuntime.interpreters.main->id_mutex = PyThread_allocate_lock(); + if (_PyRuntime.interpreters.main->id_mutex == NULL) { + Py_FatalError("Can't initialize ID lock for main interpreter"); + } + + _PyRuntime.xidregistry.mutex = PyThread_allocate_lock(); + if (_PyRuntime.xidregistry.mutex == NULL) { + Py_FatalError("Can't initialize lock for cross-interpreter data registry"); + } +} + #define HEAD_LOCK() PyThread_acquire_lock(_PyRuntime.interpreters.mutex, \ WAIT_LOCK) #define HEAD_UNLOCK() PyThread_release_lock(_PyRuntime.interpreters.mutex) -- cgit v1.2.1 From 1b304f992ddfc1cc40758dd633bc6a2595399189 Mon Sep 17 00:00:00 2001 From: tyomitch Date: Sat, 9 Mar 2019 17:35:50 +0200 Subject: Remove d_initial from the parser as it is unused (GH-12212) d_initial, the first state of a particular DFA in the parser has always been initialized to 0 in the old pgen as well as the new pgen. As this value is not used and the first state of each DFA is assumed to be the first element in the array representing it, remove d_initial from the parser to reduce complexity. --- Python/graminit.c | 184 +++++++++++++++++++++++++++--------------------------- 1 file changed, 92 insertions(+), 92 deletions(-) (limited to 'Python') diff --git a/Python/graminit.c b/Python/graminit.c index 24f6f6c72a..441502e908 100644 --- a/Python/graminit.c +++ b/Python/graminit.c @@ -2110,189 +2110,189 @@ static state states_91[11] = { {2, arcs_91_10}, }; static dfa dfas[92] = { - {256, "single_input", 0, 3, states_0, + {256, "single_input", 3, states_0, "\344\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {257, "file_input", 0, 2, states_1, + {257, "file_input", 2, states_1, "\344\377\377\377\377\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {258, "eval_input", 0, 3, states_2, + {258, "eval_input", 3, states_2, "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {259, "decorator", 0, 7, states_3, + {259, "decorator", 7, states_3, "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {260, "decorators", 0, 2, states_4, + {260, "decorators", 2, states_4, "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {261, "decorated", 0, 3, states_5, + {261, "decorated", 3, states_5, "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {262, "async_funcdef", 0, 3, states_6, + {262, "async_funcdef", 3, states_6, "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {263, "funcdef", 0, 9, states_7, + {263, "funcdef", 9, states_7, "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {264, "parameters", 0, 4, states_8, + {264, "parameters", 4, states_8, "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {265, "typedargslist", 0, 22, states_9, + {265, "typedargslist", 22, states_9, "\100\000\000\000\000\001\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {266, "tfpdef", 0, 4, states_10, + {266, "tfpdef", 4, states_10, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {267, "varargslist", 0, 18, states_11, + {267, "varargslist", 18, states_11, "\100\000\000\000\000\001\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {268, "vfpdef", 0, 2, states_12, + {268, "vfpdef", 2, states_12, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {269, "stmt", 0, 2, states_13, + {269, "stmt", 2, states_13, "\340\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {270, "simple_stmt", 0, 4, states_14, + {270, "simple_stmt", 4, states_14, "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {271, "small_stmt", 0, 2, states_15, + {271, "small_stmt", 2, states_15, "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {272, "expr_stmt", 0, 6, states_16, + {272, "expr_stmt", 6, states_16, "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {273, "annassign", 0, 5, states_17, + {273, "annassign", 5, states_17, "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {274, "testlist_star_expr", 0, 3, states_18, + {274, "testlist_star_expr", 3, states_18, "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {275, "augassign", 0, 2, states_19, + {275, "augassign", 2, states_19, "\000\000\000\000\000\000\000\000\000\000\340\377\003\000\000\000\000\000\000\000\000\000\000"}, - {276, "del_stmt", 0, 3, states_20, + {276, "del_stmt", 3, states_20, "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {277, "pass_stmt", 0, 2, states_21, + {277, "pass_stmt", 2, states_21, "\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {278, "flow_stmt", 0, 2, states_22, + {278, "flow_stmt", 2, states_22, "\000\000\005\300\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {279, "break_stmt", 0, 2, states_23, + {279, "break_stmt", 2, states_23, "\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {280, "continue_stmt", 0, 2, states_24, + {280, "continue_stmt", 2, states_24, "\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {281, "return_stmt", 0, 3, states_25, + {281, "return_stmt", 3, states_25, "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {282, "yield_stmt", 0, 2, states_26, + {282, "yield_stmt", 2, states_26, "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {283, "raise_stmt", 0, 5, states_27, + {283, "raise_stmt", 5, states_27, "\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {284, "import_stmt", 0, 2, states_28, + {284, "import_stmt", 2, states_28, "\000\000\100\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {285, "import_name", 0, 3, states_29, + {285, "import_name", 3, states_29, "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {286, "import_from", 0, 8, states_30, + {286, "import_from", 8, states_30, "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {287, "import_as_name", 0, 4, states_31, + {287, "import_as_name", 4, states_31, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {288, "dotted_as_name", 0, 4, states_32, + {288, "dotted_as_name", 4, states_32, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {289, "import_as_names", 0, 3, states_33, + {289, "import_as_names", 3, states_33, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {290, "dotted_as_names", 0, 2, states_34, + {290, "dotted_as_names", 2, states_34, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {291, "dotted_name", 0, 2, states_35, + {291, "dotted_name", 2, states_35, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {292, "global_stmt", 0, 3, states_36, + {292, "global_stmt", 3, states_36, "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {293, "nonlocal_stmt", 0, 3, states_37, + {293, "nonlocal_stmt", 3, states_37, "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {294, "assert_stmt", 0, 5, states_38, + {294, "assert_stmt", 5, states_38, "\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {295, "compound_stmt", 0, 2, states_39, + {295, "compound_stmt", 2, states_39, "\000\004\052\001\107\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {296, "async_stmt", 0, 3, states_40, + {296, "async_stmt", 3, states_40, "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {297, "if_stmt", 0, 8, states_41, + {297, "if_stmt", 8, states_41, "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {298, "while_stmt", 0, 8, states_42, + {298, "while_stmt", 8, states_42, "\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {299, "for_stmt", 0, 11, states_43, + {299, "for_stmt", 11, states_43, "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {300, "try_stmt", 0, 13, states_44, + {300, "try_stmt", 13, states_44, "\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {301, "with_stmt", 0, 6, states_45, + {301, "with_stmt", 6, states_45, "\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {302, "with_item", 0, 4, states_46, + {302, "with_item", 4, states_46, "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {303, "except_clause", 0, 5, states_47, + {303, "except_clause", 5, states_47, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"}, - {304, "suite", 0, 5, states_48, + {304, "suite", 5, states_48, "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {305, "namedexpr_test", 0, 4, states_49, + {305, "namedexpr_test", 4, states_49, "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {306, "test", 0, 6, states_50, + {306, "test", 6, states_50, "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {307, "test_nocond", 0, 2, states_51, + {307, "test_nocond", 2, states_51, "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {308, "lambdef", 0, 5, states_52, + {308, "lambdef", 5, states_52, "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {309, "lambdef_nocond", 0, 5, states_53, + {309, "lambdef_nocond", 5, states_53, "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {310, "or_test", 0, 2, states_54, + {310, "or_test", 2, states_54, "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {311, "and_test", 0, 2, states_55, + {311, "and_test", 2, states_55, "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {312, "not_test", 0, 3, states_56, + {312, "not_test", 3, states_56, "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {313, "comparison", 0, 2, states_57, + {313, "comparison", 2, states_57, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {314, "comp_op", 0, 4, states_58, + {314, "comp_op", 4, states_58, "\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\004\000\340\017\000\000\000\000"}, - {315, "star_expr", 0, 3, states_59, + {315, "star_expr", 3, states_59, "\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {316, "expr", 0, 2, states_60, + {316, "expr", 2, states_60, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {317, "xor_expr", 0, 2, states_61, + {317, "xor_expr", 2, states_61, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {318, "and_expr", 0, 2, states_62, + {318, "and_expr", 2, states_62, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {319, "shift_expr", 0, 2, states_63, + {319, "shift_expr", 2, states_63, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {320, "arith_expr", 0, 2, states_64, + {320, "arith_expr", 2, states_64, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {321, "term", 0, 2, states_65, + {321, "term", 2, states_65, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {322, "factor", 0, 3, states_66, + {322, "factor", 3, states_66, "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {323, "power", 0, 4, states_67, + {323, "power", 4, states_67, "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {324, "atom_expr", 0, 3, states_68, + {324, "atom_expr", 3, states_68, "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {325, "atom", 0, 9, states_69, + {325, "atom", 9, states_69, "\040\172\000\000\020\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {326, "testlist_comp", 0, 5, states_70, + {326, "testlist_comp", 5, states_70, "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {327, "trailer", 0, 7, states_71, + {327, "trailer", 7, states_71, "\040\100\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, - {328, "subscriptlist", 0, 3, states_72, + {328, "subscriptlist", 3, states_72, "\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {329, "subscript", 0, 5, states_73, + {329, "subscript", 5, states_73, "\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {330, "sliceop", 0, 3, states_74, + {330, "sliceop", 3, states_74, "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {331, "exprlist", 0, 3, states_75, + {331, "exprlist", 3, states_75, "\340\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {332, "testlist", 0, 3, states_76, + {332, "testlist", 3, states_76, "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {333, "dictorsetmaker", 0, 14, states_77, + {333, "dictorsetmaker", 14, states_77, "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {334, "classdef", 0, 8, states_78, + {334, "classdef", 8, states_78, "\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {335, "arglist", 0, 3, states_79, + {335, "arglist", 3, states_79, "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {336, "argument", 0, 4, states_80, + {336, "argument", 4, states_80, "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {337, "comp_iter", 0, 2, states_81, + {337, "comp_iter", 2, states_81, "\000\000\040\001\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {338, "sync_comp_for", 0, 6, states_82, + {338, "sync_comp_for", 6, states_82, "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {339, "comp_for", 0, 3, states_83, + {339, "comp_for", 3, states_83, "\000\000\040\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {340, "comp_if", 0, 4, states_84, + {340, "comp_if", 4, states_84, "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {341, "encoding_decl", 0, 2, states_85, + {341, "encoding_decl", 2, states_85, "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {342, "yield_expr", 0, 3, states_86, + {342, "yield_expr", 3, states_86, "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {343, "yield_arg", 0, 3, states_87, + {343, "yield_arg", 3, states_87, "\340\173\100\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {344, "func_body_suite", 0, 7, states_88, + {344, "func_body_suite", 7, states_88, "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {345, "func_type_input", 0, 3, states_89, + {345, "func_type_input", 3, states_89, "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {346, "func_type", 0, 6, states_90, + {346, "func_type", 6, states_90, "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {347, "typelist", 0, 11, states_91, + {347, "typelist", 11, states_91, "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, }; static label labels[183] = { -- cgit v1.2.1 From 9776b0636ae39668d3ce1c006d4be01dad01bf9f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 13 Mar 2019 17:55:01 +0100 Subject: bpo-36262: Fix _Py_dg_strtod() memory leak (goto undfl) (GH-12276) Fix an unlikely memory leak on conversion from string to float in the function _Py_dg_strtod() used by float(str), complex(str), pickle.load(), marshal.load(), etc. Fix an unlikely memory leak in _Py_dg_strtod() on "undfl:" label: rewrite memory management in this function to always release all memory before exiting the function. Initialize variables to NULL, and set them to NULL after calling Bfree() at the "cont:" label. Note: Bfree(NULL) is well defined: it does nothing. --- Python/dtoa.c | 79 +++++++++++++++++++---------------------------------------- 1 file changed, 25 insertions(+), 54 deletions(-) (limited to 'Python') diff --git a/Python/dtoa.c b/Python/dtoa.c index 01ca9b0b22..b7bb7acfb6 100644 --- a/Python/dtoa.c +++ b/Python/dtoa.c @@ -1441,8 +1441,9 @@ _Py_dg_strtod(const char *s00, char **se) ULong y, z, abs_exp; Long L; BCinfo bc; - Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; + Bigint *bb = NULL, *bd = NULL, *bd0 = NULL, *bs = NULL, *delta = NULL; size_t ndigits, fraclen; + double result; dval(&rv) = 0.; @@ -1634,7 +1635,6 @@ _Py_dg_strtod(const char *s00, char **se) if (k > 9) { dval(&rv) = tens[k - 9] * dval(&rv) + z; } - bd0 = 0; if (nd <= DBL_DIG && Flt_Rounds == 1 ) { @@ -1804,14 +1804,11 @@ _Py_dg_strtod(const char *s00, char **se) bd = Balloc(bd0->k); if (bd == NULL) { - Bfree(bd0); goto failed_malloc; } Bcopy(bd, bd0); bb = sd2b(&rv, bc.scale, &bbe); /* srv = bb * 2^bbe */ if (bb == NULL) { - Bfree(bd); - Bfree(bd0); goto failed_malloc; } /* Record whether lsb of bb is odd, in case we need this @@ -1821,9 +1818,6 @@ _Py_dg_strtod(const char *s00, char **se) /* tdv = bd * 10**e; srv = bb * 2**bbe */ bs = i2b(1); if (bs == NULL) { - Bfree(bb); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } @@ -1874,54 +1868,36 @@ _Py_dg_strtod(const char *s00, char **se) if (bb5 > 0) { bs = pow5mult(bs, bb5); if (bs == NULL) { - Bfree(bb); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } - bb1 = mult(bs, bb); + Bigint *bb1 = mult(bs, bb); Bfree(bb); bb = bb1; if (bb == NULL) { - Bfree(bs); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } } if (bb2 > 0) { bb = lshift(bb, bb2); if (bb == NULL) { - Bfree(bs); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } } if (bd5 > 0) { bd = pow5mult(bd, bd5); if (bd == NULL) { - Bfree(bb); - Bfree(bs); - Bfree(bd0); goto failed_malloc; } } if (bd2 > 0) { bd = lshift(bd, bd2); if (bd == NULL) { - Bfree(bb); - Bfree(bs); - Bfree(bd0); goto failed_malloc; } } if (bs2 > 0) { bs = lshift(bs, bs2); if (bs == NULL) { - Bfree(bb); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } } @@ -1932,10 +1908,6 @@ _Py_dg_strtod(const char *s00, char **se) delta = diff(bb, bd); if (delta == NULL) { - Bfree(bb); - Bfree(bs); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } dsign = delta->sign; @@ -1989,10 +1961,6 @@ _Py_dg_strtod(const char *s00, char **se) } delta = lshift(delta,Log2P); if (delta == NULL) { - Bfree(bb); - Bfree(bs); - Bfree(bd); - Bfree(bd0); goto failed_malloc; } if (cmp(delta, bs) > 0) @@ -2094,11 +2062,6 @@ _Py_dg_strtod(const char *s00, char **se) if ((word0(&rv) & Exp_mask) >= Exp_msk1*(DBL_MAX_EXP+Bias-P)) { if (word0(&rv0) == Big0 && word1(&rv0) == Big1) { - Bfree(bb); - Bfree(bd); - Bfree(bs); - Bfree(bd0); - Bfree(delta); goto ovfl; } word0(&rv) = Big0; @@ -2140,16 +2103,11 @@ _Py_dg_strtod(const char *s00, char **se) } } cont: - Bfree(bb); - Bfree(bd); - Bfree(bs); - Bfree(delta); + Bfree(bb); bb = NULL; + Bfree(bd); bd = NULL; + Bfree(bs); bs = NULL; + Bfree(delta); delta = NULL; } - Bfree(bb); - Bfree(bd); - Bfree(bs); - Bfree(bd0); - Bfree(delta); if (bc.nd > nd) { error = bigcomp(&rv, s0, &bc); if (error) @@ -2163,24 +2121,37 @@ _Py_dg_strtod(const char *s00, char **se) } ret: - return sign ? -dval(&rv) : dval(&rv); + result = sign ? -dval(&rv) : dval(&rv); + goto done; parse_error: - return 0.0; + result = 0.0; + goto done; failed_malloc: errno = ENOMEM; - return -1.0; + result = -1.0; + goto done; undfl: - return sign ? -0.0 : 0.0; + result = sign ? -0.0 : 0.0; + goto done; ovfl: errno = ERANGE; /* Can't trust HUGE_VAL */ word0(&rv) = Exp_mask; word1(&rv) = 0; - return sign ? -dval(&rv) : dval(&rv); + result = sign ? -dval(&rv) : dval(&rv); + goto done; + + done: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); + return result; } -- cgit v1.2.1 From 10f8ce66884cd7fee2372b8dae08ca8132091574 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 13 Mar 2019 13:00:46 -0700 Subject: bpo-36280: Add Constant.kind field (GH-12295) The value is a string for string and byte literals, None otherwise. It is 'u' for u"..." literals, 'b' for b"..." literals, '' for "..." literals. The 'r' (raw) prefix is ignored. Does not apply to f-strings. This appears sufficient to make mypy capable of using the stdlib ast module instead of typed_ast (assuming a mypy patch I'm working on). WIP: I need to make the tests pass. @ilevkivskyi @serhiy-storchaka https://bugs.python.org/issue36280 --- Python/Python-ast.c | 32 +++++++++++++++++++++++++++----- Python/ast.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 73 insertions(+), 12 deletions(-) (limited to 'Python') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 0411f9f07f..d0416eb639 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -324,8 +324,10 @@ static char *JoinedStr_fields[]={ "values", }; static PyTypeObject *Constant_type; +_Py_IDENTIFIER(kind); static char *Constant_fields[]={ "value", + "kind", }; static PyTypeObject *Attribute_type; _Py_IDENTIFIER(attr); @@ -950,7 +952,7 @@ static int init_types(void) if (!FormattedValue_type) return 0; JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); if (!JoinedStr_type) return 0; - Constant_type = make_type("Constant", expr_type, Constant_fields, 1); + Constant_type = make_type("Constant", expr_type, Constant_fields, 2); if (!Constant_type) return 0; Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); if (!Attribute_type) return 0; @@ -2287,8 +2289,8 @@ JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int } expr_ty -Constant(constant value, int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena) +Constant(constant value, string kind, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!value) { @@ -2301,6 +2303,7 @@ Constant(constant value, int lineno, int col_offset, int end_lineno, int return NULL; p->kind = Constant_kind; p->v.Constant.value = value; + p->v.Constant.kind = kind; p->lineno = lineno; p->col_offset = col_offset; p->end_lineno = end_lineno; @@ -3507,6 +3510,11 @@ ast2obj_expr(void* _o) if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); + value = ast2obj_string(o->v.Constant.kind); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kind, value) == -1) + goto failed; + Py_DECREF(value); break; case Attribute_kind: result = PyType_GenericNew(Attribute_type, NULL, NULL); @@ -7224,6 +7232,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } if (isinstance) { constant value; + string kind; if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { return 1; @@ -7238,8 +7247,21 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Constant(value, lineno, col_offset, end_lineno, end_col_offset, - arena); + if (_PyObject_LookupAttrId(obj, &PyId_kind, &tmp) < 0) { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + kind = NULL; + } + else { + int res; + res = obj2ast_string(tmp, &kind, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + *out = Constant(value, kind, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } diff --git a/Python/ast.c b/Python/ast.c index d4ee1b351f..971b8ddc8c 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2313,13 +2313,13 @@ ast_for_atom(struct compiling *c, const node *n) size_t len = strlen(s); if (len >= 4 && len <= 5) { if (!strcmp(s, "None")) - return Constant(Py_None, LINENO(n), n->n_col_offset, + return Constant(Py_None, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); if (!strcmp(s, "True")) - return Constant(Py_True, LINENO(n), n->n_col_offset, + return Constant(Py_True, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); if (!strcmp(s, "False")) - return Constant(Py_False, LINENO(n), n->n_col_offset, + return Constant(Py_False, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); } name = new_identifier(s, c); @@ -2374,11 +2374,11 @@ ast_for_atom(struct compiling *c, const node *n) Py_DECREF(pynum); return NULL; } - return Constant(pynum, LINENO(n), n->n_col_offset, + return Constant(pynum, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); } case ELLIPSIS: /* Ellipsis */ - return Constant(Py_Ellipsis, LINENO(n), n->n_col_offset, + return Constant(Py_Ellipsis, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); case LPAR: /* some parenthesized expressions */ ch = CHILD(n, 1); @@ -5388,18 +5388,57 @@ FstringParser_Dealloc(FstringParser *state) ExprList_Dealloc(&state->expr_list); } +/* Constants for the following */ +static PyObject *u_kind; + +/* Compute 'kind' field for string Constant (either 'u' or None) */ +static PyObject * +make_kind(struct compiling *c, const node *n) +{ + char *s = NULL; + PyObject *kind = NULL; + + /* Find the first string literal, if any */ + while (TYPE(n) != STRING) { + if (NCH(n) == 0) + return NULL; + n = CHILD(n, 0); + } + REQ(n, STRING); + + /* If it starts with 'u', return a PyUnicode "u" string */ + s = STR(n); + if (s && *s == 'u') { + if (!u_kind) { + u_kind = PyUnicode_InternFromString("u"); + if (!u_kind) + return NULL; + } + kind = u_kind; + if (PyArena_AddPyObject(c->c_arena, kind) < 0) { + return NULL; + } + Py_INCREF(kind); + } + return kind; +} + /* Make a Constant node, but decref the PyUnicode object being added. */ static expr_ty make_str_node_and_del(PyObject **str, struct compiling *c, const node* n) { PyObject *s = *str; + PyObject *kind = NULL; *str = NULL; assert(PyUnicode_CheckExact(s)); if (PyArena_AddPyObject(c->c_arena, s) < 0) { Py_DECREF(s); return NULL; } - return Constant(s, LINENO(n), n->n_col_offset, + kind = make_kind(c, n); + if (kind == NULL && PyErr_Occurred()) + return NULL; + return Constant(s, kind, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); } @@ -5774,7 +5813,7 @@ parsestrplus(struct compiling *c, const node *n) /* Just return the bytes object and we're done. */ if (PyArena_AddPyObject(c->c_arena, bytes_str) < 0) goto error; - return Constant(bytes_str, LINENO(n), n->n_col_offset, + return Constant(bytes_str, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); } -- cgit v1.2.1 From d53fe5f407ff4b529628b01a1bcbf21a6aad5c3a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 13 Mar 2019 22:59:55 +0200 Subject: bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264) --- Python/coreconfig.c | 2 +- Python/dynload_win.c | 2 +- Python/getargs.c | 10 +++++----- Python/hamt.c | 2 +- Python/pyarena.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index cd4ef22ff6..845e4c9a16 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1103,7 +1103,7 @@ get_locale_encoding(char **locale_encoding) { #ifdef MS_WINDOWS char encoding[20]; - PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP()); + PyOS_snprintf(encoding, sizeof(encoding), "cp%u", GetACP()); #elif defined(__ANDROID__) || defined(__VXWORKS__) const char *encoding = "UTF-8"; #else diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 129e04d1b2..36918c3579 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -256,7 +256,7 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, This should not happen if called correctly. */ if (theLength == 0) { message = PyUnicode_FromFormat( - "DLL load failed with error code %d", + "DLL load failed with error code %u", errorCode); } else { /* For some reason a \r\n diff --git a/Python/getargs.c b/Python/getargs.c index ba1a9d4214..876f5c76d2 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -372,14 +372,14 @@ vgetargs1_impl(PyObject *compat_args, PyObject *const *stack, Py_ssize_t nargs, if (nargs < min || max < nargs) { if (message == NULL) PyErr_Format(PyExc_TypeError, - "%.150s%s takes %s %d argument%s (%ld given)", + "%.150s%s takes %s %d argument%s (%zd given)", fname==NULL ? "function" : fname, fname==NULL ? "" : "()", min==max ? "exactly" : nargs < min ? "at least" : "at most", nargs < min ? min : max, (nargs < min ? min : max) == 1 ? "" : "s", - Py_SAFE_DOWNCAST(nargs, Py_ssize_t, long)); + nargs); else PyErr_SetString(PyExc_TypeError, message); return cleanreturn(0, &freelist); @@ -1741,7 +1741,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, else { PyErr_Format(PyExc_TypeError, "%.200s%s takes %s %d positional argument%s" - " (%d given)", + " (%zd given)", (fname == NULL) ? "function" : fname, (fname == NULL) ? "" : "()", (min != INT_MAX) ? "at most" : "exactly", @@ -1826,7 +1826,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, if (skip) { PyErr_Format(PyExc_TypeError, "%.200s%s takes %s %d positional argument%s" - " (%d given)", + " (%zd given)", (fname == NULL) ? "function" : fname, (fname == NULL) ? "" : "()", (Py_MIN(pos, min) < i) ? "at least" : "exactly", @@ -2194,7 +2194,7 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs, Py_ssize_t min = Py_MIN(pos, parser->min); PyErr_Format(PyExc_TypeError, "%.200s%s takes %s %d positional argument%s" - " (%d given)", + " (%zd given)", (parser->fname == NULL) ? "function" : parser->fname, (parser->fname == NULL) ? "" : "()", min < parser->max ? "at least" : "exactly", diff --git a/Python/hamt.c b/Python/hamt.c index aa90d37240..67af04c437 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -2005,7 +2005,7 @@ hamt_node_array_dump(PyHamtNode_Array *node, goto error; } - if (_hamt_dump_format(writer, "%d::\n", i)) { + if (_hamt_dump_format(writer, "%zd::\n", i)) { goto error; } diff --git a/Python/pyarena.c b/Python/pyarena.c index abb5729c8a..aefb787e55 100644 --- a/Python/pyarena.c +++ b/Python/pyarena.c @@ -160,7 +160,7 @@ PyArena_Free(PyArena *arena) #if defined(Py_DEBUG) /* fprintf(stderr, - "alloc=%d size=%d blocks=%d block_size=%d big=%d objects=%d\n", + "alloc=%zu size=%zu blocks=%zu block_size=%zu big=%zu objects=%zu\n", arena->total_allocs, arena->total_size, arena->total_blocks, arena->total_block_size, arena->total_big_blocks, PyList_Size(arena->a_objects)); -- cgit v1.2.1 From f2f55e7f03d332fd43bc665a86d585a79c3b3ed4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 13 Mar 2019 23:03:22 +0200 Subject: bpo-36282: Improved error message for too much positional arguments. (GH-12310) --- Python/getargs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/getargs.c b/Python/getargs.c index 876f5c76d2..77ded609ee 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2137,7 +2137,7 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs, "%.200s%s takes %s %d positional argument%s (%d given)", (parser->fname == NULL) ? "function" : parser->fname, (parser->fname == NULL) ? "" : "()", - (parser->min != INT_MAX) ? "at most" : "exactly", + (parser->min < parser->max) ? "at most" : "exactly", parser->max, parser->max == 1 ? "" : "s", nargs); -- cgit v1.2.1 From 2c0d3f454705bb5ccf5f6189f3cf77bbae4f056b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 14 Mar 2019 10:06:05 +0200 Subject: bpo-36254: Fix yet one invalid use of %d in format string in C. (GH-12318) --- Python/getargs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/getargs.c b/Python/getargs.c index 77ded609ee..05ebe9c45b 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2134,7 +2134,7 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs, } else { PyErr_Format(PyExc_TypeError, - "%.200s%s takes %s %d positional argument%s (%d given)", + "%.200s%s takes %s %d positional argument%s (%zd given)", (parser->fname == NULL) ? "function" : parser->fname, (parser->fname == NULL) ? "" : "()", (parser->min < parser->max) ? "at most" : "exactly", -- cgit v1.2.1 From 3191391515824fa7f3c573d807f1034c6a28fab3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 14 Mar 2019 10:32:22 +0200 Subject: bpo-36127: Argument Clinic: inline parsing code for keyword parameters. (GH-12058) --- Python/clinic/_warnings.c.h | 44 +++++- Python/clinic/bltinmodule.c.h | 110 +++++++++++++-- Python/clinic/import.c.h | 25 +++- Python/clinic/sysmodule.c.h | 18 ++- Python/clinic/traceback.c.h | 35 ++++- Python/getargs.c | 320 ++++++++++++++++++++++++++++++++++-------- 6 files changed, 471 insertions(+), 81 deletions(-) (limited to 'Python') diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h index d1e50de7d9..67ab0e3d9d 100644 --- a/Python/clinic/_warnings.c.h +++ b/Python/clinic/_warnings.c.h @@ -20,19 +20,55 @@ warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec { PyObject *return_value = NULL; static const char * const _keywords[] = {"message", "category", "stacklevel", "source", NULL}; - static _PyArg_Parser _parser = {"O|OnO:warn", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "warn", 0}; + PyObject *argsbuf[4]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *message; PyObject *category = Py_None; Py_ssize_t stacklevel = 1; PyObject *source = Py_None; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &message, &category, &stacklevel, &source)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf); + if (!args) { goto exit; } + message = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + if (args[1]) { + category = args[1]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (args[2]) { + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + stacklevel = ival; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + source = args[3]; +skip_optional_pos: return_value = warnings_warn_impl(module, message, category, stacklevel, source); exit: return return_value; } -/*[clinic end generated code: output=a4fbe6e2d1cc2091 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b7bb54c73b5433ec input=a9049054013a1b77]*/ diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index df9970942b..0ed11bceeb 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -180,7 +180,9 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj { PyObject *return_value = NULL; static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "feature_version", NULL}; - static _PyArg_Parser _parser = {"OO&s|iiii:compile", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "compile", 0}; + PyObject *argsbuf[7]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; PyObject *source; PyObject *filename; const char *mode; @@ -189,10 +191,82 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj int optimize = -1; int feature_version = -1; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize, &feature_version)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 7, 0, argsbuf); + if (!args) { goto exit; } + source = args[0]; + if (!PyUnicode_FSDecoder(args[1], &filename)) { + goto exit; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("compile", 3, "str", args[2]); + goto exit; + } + Py_ssize_t mode_length; + mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length); + if (mode == NULL) { + goto exit; + } + if (strlen(mode) != (size_t)mode_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[3]) { + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[3]); + if (flags == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (args[4]) { + if (PyFloat_Check(args[4])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + dont_inherit = _PyLong_AsInt(args[4]); + if (dont_inherit == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (args[5]) { + if (PyFloat_Check(args[5])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + optimize = _PyLong_AsInt(args[5]); + if (optimize == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[6])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + feature_version = _PyLong_AsInt(args[6]); + if (feature_version == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version); exit: @@ -637,14 +711,22 @@ builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec { PyObject *return_value = NULL; static const char * const _keywords[] = {"number", "ndigits", NULL}; - static _PyArg_Parser _parser = {"O|O:round", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "round", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *number; PyObject *ndigits = NULL; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &number, &ndigits)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } + number = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + ndigits = args[1]; +skip_optional_pos: return_value = builtin_round_impl(module, number, ndigits); exit: @@ -672,14 +754,22 @@ builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "start", NULL}; - static _PyArg_Parser _parser = {"O|O:sum", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "sum", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *iterable; PyObject *start = NULL; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &iterable, &start)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } + iterable = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + start = args[1]; +skip_optional_pos: return_value = builtin_sum_impl(module, iterable, start); exit: @@ -755,4 +845,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=00b97a48ea49eaf2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3f690311ac556c31 input=a9049054013a1b77]*/ diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h index 9ee20fbe50..05e3106bb3 100644 --- a/Python/clinic/import.c.h +++ b/Python/clinic/import.c.h @@ -411,12 +411,29 @@ _imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "source", NULL}; - static _PyArg_Parser _parser = {"ly*:source_hash", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "source_hash", 0}; + PyObject *argsbuf[2]; long key; Py_buffer source = {NULL, NULL}; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &key, &source)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + key = PyLong_AsLong(args[0]); + if (key == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &source, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&source, 'C')) { + _PyArg_BadArgument("source_hash", 2, "contiguous buffer", args[1]); goto exit; } return_value = _imp_source_hash_impl(module, key, &source); @@ -437,4 +454,4 @@ exit: #ifndef _IMP_EXEC_DYNAMIC_METHODDEF #define _IMP_EXEC_DYNAMIC_METHODDEF #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */ -/*[clinic end generated code: output=2409b8feeafe7c4b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b51244770fdcf4b8 input=a9049054013a1b77]*/ diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index fc9794bf25..c70b721983 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -410,11 +410,21 @@ sys_set_coroutine_origin_tracking_depth(PyObject *module, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = {"depth", NULL}; - static _PyArg_Parser _parser = {"i:set_coroutine_origin_tracking_depth", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "set_coroutine_origin_tracking_depth", 0}; + PyObject *argsbuf[1]; int depth; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &depth)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + depth = _PyLong_AsInt(args[0]); + if (depth == -1 && PyErr_Occurred()) { goto exit; } return_value = sys_set_coroutine_origin_tracking_depth_impl(module, depth); @@ -1050,4 +1060,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF #define SYS_GETANDROIDAPILEVEL_METHODDEF #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */ -/*[clinic end generated code: output=109787af3401cd27 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3ba4c194d00f1866 input=a9049054013a1b77]*/ diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h index d9daccbbb7..2815f65d3d 100644 --- a/Python/clinic/traceback.c.h +++ b/Python/clinic/traceback.c.h @@ -17,14 +17,41 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL}; - static _PyArg_Parser _parser = {"OO!ii:TracebackType", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "TracebackType", 0}; + PyObject *argsbuf[4]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *tb_next; PyFrameObject *tb_frame; int tb_lasti; int tb_lineno; - if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, - &tb_next, &PyFrame_Type, &tb_frame, &tb_lasti, &tb_lineno)) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 4, 4, 0, argsbuf); + if (!fastargs) { + goto exit; + } + tb_next = fastargs[0]; + if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) { + _PyArg_BadArgument("TracebackType", 2, (&PyFrame_Type)->tp_name, fastargs[1]); + goto exit; + } + tb_frame = (PyFrameObject *)fastargs[1]; + if (PyFloat_Check(fastargs[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + tb_lasti = _PyLong_AsInt(fastargs[2]); + if (tb_lasti == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(fastargs[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + tb_lineno = _PyLong_AsInt(fastargs[3]); + if (tb_lineno == -1 && PyErr_Occurred()) { goto exit; } return_value = tb_new_impl(type, tb_next, tb_frame, tb_lasti, tb_lineno); @@ -32,4 +59,4 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=0133130d7d19556f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7e4c0e252d0973b0 input=a9049054013a1b77]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 05ebe9c45b..693a29cced 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1905,24 +1905,11 @@ parser_init(struct _PyArg_Parser *parser) int i, len, min, max, nkw; PyObject *kwtuple; - assert(parser->format != NULL); assert(parser->keywords != NULL); if (parser->kwtuple != NULL) { return 1; } - /* grab the function name or custom error msg first (mutually exclusive) */ - parser->fname = strchr(parser->format, ':'); - if (parser->fname) { - parser->fname++; - parser->custom_msg = NULL; - } - else { - parser->custom_msg = strchr(parser->format,';'); - if (parser->custom_msg) - parser->custom_msg++; - } - keywords = parser->keywords; /* scan keywords and count the number of positional-only parameters */ for (i = 0; keywords[i] && !*keywords[i]; i++) { @@ -1938,60 +1925,74 @@ parser_init(struct _PyArg_Parser *parser) } len = i; - min = max = INT_MAX; format = parser->format; - for (i = 0; i < len; i++) { - if (*format == '|') { - if (min != INT_MAX) { - PyErr_SetString(PyExc_SystemError, - "Invalid format string (| specified twice)"); - return 0; + if (format) { + /* grab the function name or custom error msg first (mutually exclusive) */ + parser->fname = strchr(parser->format, ':'); + if (parser->fname) { + parser->fname++; + parser->custom_msg = NULL; + } + else { + parser->custom_msg = strchr(parser->format,';'); + if (parser->custom_msg) + parser->custom_msg++; + } + + min = max = INT_MAX; + for (i = 0; i < len; i++) { + if (*format == '|') { + if (min != INT_MAX) { + PyErr_SetString(PyExc_SystemError, + "Invalid format string (| specified twice)"); + return 0; + } + if (max != INT_MAX) { + PyErr_SetString(PyExc_SystemError, + "Invalid format string ($ before |)"); + return 0; + } + min = i; + format++; } - if (max != INT_MAX) { - PyErr_SetString(PyExc_SystemError, - "Invalid format string ($ before |)"); - return 0; + if (*format == '$') { + if (max != INT_MAX) { + PyErr_SetString(PyExc_SystemError, + "Invalid format string ($ specified twice)"); + return 0; + } + if (i < parser->pos) { + PyErr_SetString(PyExc_SystemError, + "Empty parameter name after $"); + return 0; + } + max = i; + format++; } - min = i; - format++; - } - if (*format == '$') { - if (max != INT_MAX) { - PyErr_SetString(PyExc_SystemError, - "Invalid format string ($ specified twice)"); + if (IS_END_OF_FORMAT(*format)) { + PyErr_Format(PyExc_SystemError, + "More keyword list entries (%d) than " + "format specifiers (%d)", len, i); return 0; } - if (i < parser->pos) { - PyErr_SetString(PyExc_SystemError, - "Empty parameter name after $"); + + msg = skipitem(&format, NULL, 0); + if (msg) { + PyErr_Format(PyExc_SystemError, "%s: '%s'", msg, + format); return 0; } - max = i; - format++; - } - if (IS_END_OF_FORMAT(*format)) { - PyErr_Format(PyExc_SystemError, - "More keyword list entries (%d) than " - "format specifiers (%d)", len, i); - return 0; } + parser->min = Py_MIN(min, len); + parser->max = Py_MIN(max, len); - msg = skipitem(&format, NULL, 0); - if (msg) { - PyErr_Format(PyExc_SystemError, "%s: '%s'", msg, - format); + if (!IS_END_OF_FORMAT(*format) && (*format != '|') && (*format != '$')) { + PyErr_Format(PyExc_SystemError, + "more argument specifiers than keyword list entries " + "(remaining format:'%s')", format); return 0; } } - parser->min = Py_MIN(min, len); - parser->max = Py_MIN(max, len); - - if (!IS_END_OF_FORMAT(*format) && (*format != '|') && (*format != '$')) { - PyErr_Format(PyExc_SystemError, - "more argument specifiers than keyword list entries " - "(remaining format:'%s')", format); - return 0; - } nkw = len - parser->pos; kwtuple = PyTuple_New(nkw); @@ -2313,6 +2314,215 @@ vgetargskeywordsfast(PyObject *args, PyObject *keywords, } +#undef _PyArg_UnpackKeywords + +PyObject * const * +_PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs, + PyObject *kwargs, PyObject *kwnames, + struct _PyArg_Parser *parser, + int minpos, int maxpos, int minkw, + PyObject **buf) +{ + PyObject *kwtuple; + PyObject *keyword; + int i, posonly, minposonly, maxargs; + int reqlimit = minkw ? maxpos + minkw : minpos; + Py_ssize_t nkwargs; + PyObject *current_arg; + PyObject * const *kwstack = NULL; + + assert(kwargs == NULL || PyDict_Check(kwargs)); + assert(kwargs == NULL || kwnames == NULL); + + if (parser == NULL) { + PyErr_BadInternalCall(); + return NULL; + } + + if (kwnames != NULL && !PyTuple_Check(kwnames)) { + PyErr_BadInternalCall(); + return NULL; + } + + if (args == NULL && nargs == 0) { + args = buf; + } + + if (!parser_init(parser)) { + return NULL; + } + + kwtuple = parser->kwtuple; + posonly = parser->pos; + minposonly = Py_MIN(posonly, minpos); + maxargs = posonly + (int)PyTuple_GET_SIZE(kwtuple); + + if (kwargs != NULL) { + nkwargs = PyDict_GET_SIZE(kwargs); + } + else if (kwnames != NULL) { + nkwargs = PyTuple_GET_SIZE(kwnames); + kwstack = args + nargs; + } + else { + nkwargs = 0; + } + if (nkwargs == 0 && minkw == 0 && minpos <= nargs && nargs <= maxpos) { + /* Fast path. */ + return args; + } + if (nargs + nkwargs > maxargs) { + /* Adding "keyword" (when nargs == 0) prevents producing wrong error + messages in some special cases (see bpo-31229). */ + PyErr_Format(PyExc_TypeError, + "%.200s%s takes at most %d %sargument%s (%zd given)", + (parser->fname == NULL) ? "function" : parser->fname, + (parser->fname == NULL) ? "" : "()", + maxargs, + (nargs == 0) ? "keyword " : "", + (maxargs == 1) ? "" : "s", + nargs + nkwargs); + return NULL; + } + if (nargs > maxpos) { + if (maxpos == 0) { + PyErr_Format(PyExc_TypeError, + "%.200s%s takes no positional arguments", + (parser->fname == NULL) ? "function" : parser->fname, + (parser->fname == NULL) ? "" : "()"); + } + else { + PyErr_Format(PyExc_TypeError, + "%.200s%s takes %s %d positional argument%s (%zd given)", + (parser->fname == NULL) ? "function" : parser->fname, + (parser->fname == NULL) ? "" : "()", + (minpos < maxpos) ? "at most" : "exactly", + maxpos, + (maxpos == 1) ? "" : "s", + nargs); + } + return NULL; + } + if (nargs < minposonly) { + PyErr_Format(PyExc_TypeError, + "%.200s%s takes %s %d positional argument%s" + " (%zd given)", + (parser->fname == NULL) ? "function" : parser->fname, + (parser->fname == NULL) ? "" : "()", + minposonly < maxpos ? "at least" : "exactly", + minposonly, + minposonly == 1 ? "" : "s", + nargs); + return NULL; + } + + /* copy tuple args */ + for (i = 0; i < nargs; i++) { + buf[i] = args[i]; + } + + /* copy keyword args using kwtuple to drive process */ + for (i = Py_MAX(nargs, posonly); i < maxargs; i++) { + if (nkwargs) { + keyword = PyTuple_GET_ITEM(kwtuple, i - posonly); + if (kwargs != NULL) { + current_arg = PyDict_GetItemWithError(kwargs, keyword); + if (!current_arg && PyErr_Occurred()) { + return NULL; + } + } + else { + current_arg = find_keyword(kwnames, kwstack, keyword); + } + } + else if (i >= reqlimit) { + break; + } + else { + current_arg = NULL; + } + + buf[i] = current_arg; + + if (current_arg) { + --nkwargs; + } + else if (i < minpos || (maxpos <= i && i < reqlimit)) { + /* Less arguments than required */ + keyword = PyTuple_GET_ITEM(kwtuple, i - posonly); + PyErr_Format(PyExc_TypeError, "%.200s%s missing required " + "argument '%U' (pos %d)", + (parser->fname == NULL) ? "function" : parser->fname, + (parser->fname == NULL) ? "" : "()", + keyword, i+1); + return NULL; + } + } + + if (nkwargs > 0) { + Py_ssize_t j; + /* make sure there are no arguments given by name and position */ + for (i = posonly; i < nargs; i++) { + keyword = PyTuple_GET_ITEM(kwtuple, i - posonly); + if (kwargs != NULL) { + current_arg = PyDict_GetItemWithError(kwargs, keyword); + if (!current_arg && PyErr_Occurred()) { + return NULL; + } + } + else { + current_arg = find_keyword(kwnames, kwstack, keyword); + } + if (current_arg) { + /* arg present in tuple and in dict */ + PyErr_Format(PyExc_TypeError, + "argument for %.200s%s given by name ('%U') " + "and position (%d)", + (parser->fname == NULL) ? "function" : parser->fname, + (parser->fname == NULL) ? "" : "()", + keyword, i+1); + return NULL; + } + } + /* make sure there are no extraneous keyword arguments */ + j = 0; + while (1) { + int match; + if (kwargs != NULL) { + if (!PyDict_Next(kwargs, &j, &keyword, NULL)) + break; + } + else { + if (j >= PyTuple_GET_SIZE(kwnames)) + break; + keyword = PyTuple_GET_ITEM(kwnames, j); + j++; + } + + if (!PyUnicode_Check(keyword)) { + PyErr_SetString(PyExc_TypeError, + "keywords must be strings"); + return NULL; + } + match = PySequence_Contains(kwtuple, keyword); + if (match <= 0) { + if (!match) { + PyErr_Format(PyExc_TypeError, + "'%U' is an invalid keyword " + "argument for %.200s%s", + keyword, + (parser->fname == NULL) ? "this function" : parser->fname, + (parser->fname == NULL) ? "" : "()"); + } + return NULL; + } + } + } + + return buf; +} + + static const char * skipitem(const char **p_format, va_list *p_va, int flags) { -- cgit v1.2.1 From 74f6568bbd3e70806ea3219e8bacb386ad802ccf Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Mar 2019 15:08:05 +0100 Subject: bpo-36301: Add _PyWstrList structure (GH-12343) Replace messy _Py_wstrlist_xxx() functions with a new clean _PyWstrList structure and new _PyWstrList_xxx() functions. Changes: * Add _PyCoreConfig.use_module_search_paths to decide if _PyCoreConfig.module_search_paths should be computed or not, to support empty search path list. * _PyWstrList_Clear() sets length to 0 and items to NULL, whereas _Py_wstrlist_clear() only freed memory. * _PyWstrList_Append() returns an int, whereas _Py_wstrlist_append() returned _PyInitError. * _PyWstrList uses Py_ssize_t for the length, instead of int. * Replace (int, wchar_t**) with _PyWstrList in: * _PyPreConfig * _PyCoreConfig * _PyPreCmdline * _PyCmdline * Replace "int orig_argv; wchar_t **orig_argv;" with "_PyWstrList orig_argv". * _PyCmdline and _PyPreCmdline now also copy wchar_argv. * Rename _PyArgv_Decode() to _PyArgv_AsWstrList(). * PySys_SetArgvEx() now pass the fixed (argc, argv) to _PyPathConfig_ComputeArgv0() (don't pass negative argc or NULL argv). * _PyOS_GetOpt() uses Py_ssize_t --- Python/coreconfig.c | 364 ++++++++++++++++++++++++---------------------------- Python/getopt.c | 8 +- Python/pathconfig.c | 40 +++--- Python/preconfig.c | 69 +++++----- Python/sysmodule.c | 43 ++++--- 5 files changed, 241 insertions(+), 283 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 845e4c9a16..15107fa36c 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -202,81 +202,128 @@ fail: } -/* --- _Py_wstrlist ----------------------------------------------- */ +/* --- _PyWstrList ------------------------------------------------ */ + +#ifndef NDEBUG +int +_PyWstrList_CheckConsistency(const _PyWstrList *list) +{ + assert(list->length >= 0); + if (list->length != 0) { + assert(list->items != NULL); + } + for (Py_ssize_t i = 0; i < list->length; i++) { + assert(list->items[i] != NULL); + } + return 1; +} +#endif /* Py_DEBUG */ + void -_Py_wstrlist_clear(int len, wchar_t **list) +_PyWstrList_Clear(_PyWstrList *list) { - for (int i=0; i < len; i++) { - PyMem_RawFree(list[i]); + assert(_PyWstrList_CheckConsistency(list)); + for (Py_ssize_t i=0; i < list->length; i++) { + PyMem_RawFree(list->items[i]); } - PyMem_RawFree(list); + PyMem_RawFree(list->items); + list->length = 0; + list->items = NULL; } -wchar_t** -_Py_wstrlist_copy(int len, wchar_t * const *list) +int +_PyWstrList_Copy(_PyWstrList *list, const _PyWstrList *list2) { - assert((len > 0 && list != NULL) || len == 0); - size_t size = len * sizeof(list[0]); - wchar_t **list_copy = PyMem_RawMalloc(size); - if (list_copy == NULL) { - return NULL; + assert(_PyWstrList_CheckConsistency(list)); + assert(_PyWstrList_CheckConsistency(list2)); + + if (list2->length == 0) { + _PyWstrList_Clear(list); + return 0; } - for (int i=0; i < len; i++) { - wchar_t* arg = _PyMem_RawWcsdup(list[i]); - if (arg == NULL) { - _Py_wstrlist_clear(i, list_copy); - return NULL; + + _PyWstrList copy = _PyWstrList_INIT; + + size_t size = list2->length * sizeof(list2->items[0]); + copy.items = PyMem_RawMalloc(size); + if (copy.items == NULL) { + return -1; + } + + for (Py_ssize_t i=0; i < list2->length; i++) { + wchar_t *item = _PyMem_RawWcsdup(list2->items[i]); + if (item == NULL) { + _PyWstrList_Clear(©); + return -1; } - list_copy[i] = arg; + copy.items[i] = item; + copy.length = i + 1; } - return list_copy; + + _PyWstrList_Clear(list); + *list = copy; + return 0; } -_PyInitError -_Py_wstrlist_append(int *len, wchar_t ***list, const wchar_t *str) +int +_PyWstrList_Append(_PyWstrList *list, const wchar_t *item) { - if (*len == INT_MAX) { - /* len+1 would overflow */ - return _Py_INIT_NO_MEMORY(); + if (list->length == PY_SSIZE_T_MAX) { + /* lenght+1 would overflow */ + return -1; } - wchar_t *str2 = _PyMem_RawWcsdup(str); - if (str2 == NULL) { - return _Py_INIT_NO_MEMORY(); + + wchar_t *item2 = _PyMem_RawWcsdup(item); + if (item2 == NULL) { + return -1; } - size_t size = (*len + 1) * sizeof(list[0]); - wchar_t **list2 = (wchar_t **)PyMem_RawRealloc(*list, size); - if (list2 == NULL) { - PyMem_RawFree(str2); - return _Py_INIT_NO_MEMORY(); + size_t size = (list->length + 1) * sizeof(list->items[0]); + wchar_t **items2 = (wchar_t **)PyMem_RawRealloc(list->items, size); + if (items2 == NULL) { + PyMem_RawFree(item2); + return -1; } - list2[*len] = str2; - *list = list2; - (*len)++; - return _Py_INIT_OK(); + + items2[list->length] = item2; + list->items = items2; + list->length++; + return 0; +} + + +static int +_PyWstrList_Extend(_PyWstrList *list, const _PyWstrList *list2) +{ + for (Py_ssize_t i = 0; i < list2->length; i++) { + if (_PyWstrList_Append(list, list2->items[i])) { + return -1; + } + } + return 0; } PyObject* -_Py_wstrlist_as_pylist(int len, wchar_t **list) +_PyWstrList_AsList(const _PyWstrList *list) { - assert(list != NULL || len < 1); + assert(_PyWstrList_CheckConsistency(list)); - PyObject *pylist = PyList_New(len); + PyObject *pylist = PyList_New(list->length); if (pylist == NULL) { return NULL; } - for (int i = 0; i < len; i++) { - PyObject *v = PyUnicode_FromWideChar(list[i], -1); - if (v == NULL) { + for (Py_ssize_t i = 0; i < list->length; i++) { + PyObject *item = PyUnicode_FromWideChar(list->items[i], -1); + if (item == NULL) { Py_DECREF(pylist); return NULL; } - PyList_SET_ITEM(pylist, i, v); + PyList_SET_ITEM(pylist, i, item); } return pylist; } @@ -369,8 +416,7 @@ _Py_ClearStandardStreamEncoding(void) /* --- Py_GetArgcArgv() ------------------------------------------- */ /* For Py_GetArgcArgv(); set by _Py_SetArgcArgv() */ -static int orig_argc = 0; -static wchar_t **orig_argv = NULL; +static _PyWstrList orig_argv = {.length = 0, .items = NULL}; void @@ -379,32 +425,22 @@ _Py_ClearArgcArgv(void) PyMemAllocatorEx old_alloc; _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - _Py_wstrlist_clear(orig_argc, orig_argv); - orig_argc = 0; - orig_argv = NULL; + _PyWstrList_Clear(&orig_argv); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } static int -_Py_SetArgcArgv(int argc, wchar_t * const *argv) +_Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv) { + const _PyWstrList argv_list = {.length = argc, .items = (wchar_t **)argv}; int res; PyMemAllocatorEx old_alloc; _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - wchar_t **argv_copy = _Py_wstrlist_copy(argc, argv); - if (argv_copy != NULL) { - _Py_ClearArgcArgv(); - orig_argc = argc; - orig_argv = argv_copy; - res = 0; - } - else { - res = -1; - } + res = _PyWstrList_Copy(&orig_argv, &argv_list); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); return res; @@ -416,8 +452,8 @@ _Py_SetArgcArgv(int argc, wchar_t * const *argv) void Py_GetArgcArgv(int *argc, wchar_t ***argv) { - *argc = orig_argc; - *argv = orig_argv; + *argc = (int)orig_argv.length; + *argv = orig_argv.items; } @@ -439,12 +475,6 @@ _PyCoreConfig_Clear(_PyCoreConfig *config) PyMem_RawFree(ATTR); \ ATTR = NULL; \ } while (0) -#define CLEAR_WSTRLIST(LEN, LIST) \ - do { \ - _Py_wstrlist_clear(LEN, LIST); \ - LEN = 0; \ - LIST = NULL; \ - } while (0) CLEAR(config->pycache_prefix); CLEAR(config->module_search_path_env); @@ -452,13 +482,11 @@ _PyCoreConfig_Clear(_PyCoreConfig *config) CLEAR(config->program_name); CLEAR(config->program); - CLEAR_WSTRLIST(config->argc, config->argv); - config->argc = -1; - - CLEAR_WSTRLIST(config->nwarnoption, config->warnoptions); - CLEAR_WSTRLIST(config->nxoption, config->xoptions); - CLEAR_WSTRLIST(config->nmodule_search_path, config->module_search_paths); - config->nmodule_search_path = -1; + _PyWstrList_Clear(&config->argv); + _PyWstrList_Clear(&config->warnoptions); + _PyWstrList_Clear(&config->xoptions); + _PyWstrList_Clear(&config->module_search_paths); + config->use_module_search_paths = 0; CLEAR(config->executable); CLEAR(config->prefix); @@ -477,7 +505,6 @@ _PyCoreConfig_Clear(_PyCoreConfig *config) CLEAR(config->run_module); CLEAR(config->run_filename); #undef CLEAR -#undef CLEAR_WSTRLIST } @@ -509,15 +536,11 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) } \ } \ } while (0) -#define COPY_WSTRLIST(LEN, LIST) \ +#define COPY_WSTRLIST(LIST) \ do { \ - if (config2->LIST != NULL) { \ - config->LIST = _Py_wstrlist_copy(config2->LEN, config2->LIST); \ - if (config->LIST == NULL) { \ - return -1; \ - } \ + if (_PyWstrList_Copy(&config->LIST, &config2->LIST) < 0 ) { \ + return -1; \ } \ - config->LEN = config2->LEN; \ } while (0) COPY_ATTR(install_signal_handlers); @@ -538,10 +561,11 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) COPY_WSTR_ATTR(program_name); COPY_WSTR_ATTR(program); - COPY_WSTRLIST(argc, argv); - COPY_WSTRLIST(nwarnoption, warnoptions); - COPY_WSTRLIST(nxoption, xoptions); - COPY_WSTRLIST(nmodule_search_path, module_search_paths); + COPY_WSTRLIST(argv); + COPY_WSTRLIST(warnoptions); + COPY_WSTRLIST(xoptions); + COPY_WSTRLIST(module_search_paths); + COPY_ATTR(use_module_search_paths); COPY_WSTR_ATTR(executable); COPY_WSTR_ATTR(prefix); @@ -817,7 +841,7 @@ config_init_executable(_PyCoreConfig *config) static const wchar_t* config_get_xoption(const _PyCoreConfig *config, wchar_t *name) { - return _Py_get_xoption(config->nxoption, config->xoptions, name); + return _Py_get_xoption(&config->xoptions, name); } @@ -1427,9 +1451,6 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) if (config->tracemalloc < 0) { config->tracemalloc = 0; } - if (config->argc < 0) { - config->argc = 0; - } if (config->filesystem_encoding == NULL || config->filesystem_errors == NULL) { err = config_init_fs_encoding(config); @@ -1449,6 +1470,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) assert(config->stdio_encoding != NULL); assert(config->stdio_errors != NULL); assert(config->_check_hash_pycs_mode != NULL); + assert(_PyWstrList_CheckConsistency(&config->argv)); return _Py_INIT_OK(); } @@ -1546,8 +1568,8 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config) : (Py_INCREF(Py_None), Py_None)) #define SET_ITEM_WSTR(ATTR) \ SET_ITEM(#ATTR, FROM_WSTRING(config->ATTR)) -#define SET_ITEM_WSTRLIST(NOPTION, OPTIONS) \ - SET_ITEM(#OPTIONS, _Py_wstrlist_as_pylist(config->NOPTION, config->OPTIONS)) +#define SET_ITEM_WSTRLIST(LIST) \ + SET_ITEM(#LIST, _PyWstrList_AsList(&config->LIST)) SET_ITEM_INT(install_signal_handlers); SET_ITEM_INT(use_hash_seed); @@ -1563,13 +1585,13 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config) SET_ITEM_STR(filesystem_errors); SET_ITEM_WSTR(pycache_prefix); SET_ITEM_WSTR(program_name); - SET_ITEM_WSTRLIST(argc, argv); + SET_ITEM_WSTRLIST(argv); SET_ITEM_WSTR(program); - SET_ITEM_WSTRLIST(nxoption, xoptions); - SET_ITEM_WSTRLIST(nwarnoption, warnoptions); + SET_ITEM_WSTRLIST(xoptions); + SET_ITEM_WSTRLIST(warnoptions); SET_ITEM_WSTR(module_search_path_env); SET_ITEM_WSTR(home); - SET_ITEM_WSTRLIST(nmodule_search_path, module_search_paths); + SET_ITEM_WSTRLIST(module_search_paths); SET_ITEM_WSTR(executable); SET_ITEM_WSTR(prefix); SET_ITEM_WSTR(base_prefix); @@ -1622,13 +1644,9 @@ fail: /* --- _PyCmdline ------------------------------------------------- */ typedef struct { - const _PyArgv *args; - int argc; - wchar_t **argv; - int nwarnoption; /* Number of -W command line options */ - wchar_t **warnoptions; /* Command line -W options */ - int nenv_warnoption; /* Number of PYTHONWARNINGS environment variables */ - wchar_t **env_warnoptions; /* PYTHONWARNINGS environment variables */ + _PyWstrList argv; + _PyWstrList warnoptions; /* Command line -W options */ + _PyWstrList env_warnoptions; /* PYTHONWARNINGS environment variables */ int print_help; /* -h, -? options */ int print_version; /* -V option */ } _PyCmdline; @@ -1637,18 +1655,9 @@ typedef struct { static void cmdline_clear(_PyCmdline *cmdline) { - _Py_wstrlist_clear(cmdline->nwarnoption, cmdline->warnoptions); - cmdline->nwarnoption = 0; - cmdline->warnoptions = NULL; - - _Py_wstrlist_clear(cmdline->nenv_warnoption, cmdline->env_warnoptions); - cmdline->nenv_warnoption = 0; - cmdline->env_warnoptions = NULL; - - if (cmdline->args->use_bytes_argv && cmdline->argv != NULL) { - _Py_wstrlist_clear(cmdline->args->argc, cmdline->argv); - } - cmdline->argv = NULL; + _PyWstrList_Clear(&cmdline->warnoptions); + _PyWstrList_Clear(&cmdline->env_warnoptions); + _PyWstrList_Clear(&cmdline->argv); } @@ -1659,11 +1668,10 @@ static _PyInitError config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, int *need_usage) { - _PyInitError err; _PyOS_ResetGetOpt(); do { int longindex = -1; - int c = _PyOS_GetOpt(cmdline->args->argc, cmdline->argv, &longindex); + int c = _PyOS_GetOpt(cmdline->argv.length, cmdline->argv.items, &longindex); if (c == EOF) { break; } @@ -1775,20 +1783,14 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, break; case 'W': - err = _Py_wstrlist_append(&cmdline->nwarnoption, - &cmdline->warnoptions, - _PyOS_optarg); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Append(&cmdline->warnoptions, _PyOS_optarg) < 0) { + return _Py_INIT_NO_MEMORY(); } break; case 'X': - err = _Py_wstrlist_append(&config->nxoption, - &config->xoptions, - _PyOS_optarg); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Append(&config->xoptions, _PyOS_optarg) < 0) { + return _Py_INIT_NO_MEMORY(); } break; @@ -1810,10 +1812,10 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, } while (1); if (config->run_command == NULL && config->run_module == NULL - && _PyOS_optind < cmdline->args->argc - && wcscmp(cmdline->argv[_PyOS_optind], L"-") != 0) + && _PyOS_optind < cmdline->argv.length + && wcscmp(cmdline->argv.items[_PyOS_optind], L"-") != 0) { - config->run_filename = _PyMem_RawWcsdup(cmdline->argv[_PyOS_optind]); + config->run_filename = _PyMem_RawWcsdup(cmdline->argv.items[_PyOS_optind]); if (config->run_filename == NULL) { return _Py_INIT_NO_MEMORY(); } @@ -1858,12 +1860,9 @@ cmdline_init_env_warnoptions(_PyCmdline *cmdline, const _PyCoreConfig *config) warning != NULL; warning = WCSTOK(NULL, L",", &context)) { - _PyInitError err = _Py_wstrlist_append(&cmdline->nenv_warnoption, - &cmdline->env_warnoptions, - warning); - if (_Py_INIT_FAILED(err)) { + if (_PyWstrList_Append(&cmdline->env_warnoptions, warning) < 0) { PyMem_RawFree(env); - return err; + return _Py_INIT_NO_MEMORY(); } } PyMem_RawFree(env); @@ -1875,8 +1874,8 @@ static _PyInitError config_init_program(_PyCoreConfig *config, const _PyCmdline *cmdline) { wchar_t *program; - if (cmdline->args->argc >= 1 && cmdline->argv != NULL) { - program = cmdline->argv[0]; + if (cmdline->argv.length >= 1) { + program = cmdline->argv.items[0]; } else { program = L""; @@ -1890,28 +1889,10 @@ config_init_program(_PyCoreConfig *config, const _PyCmdline *cmdline) } -static _PyInitError -config_add_warnings_optlist(_PyCoreConfig *config, - int len, wchar_t * const *options) -{ - for (int i = 0; i < len; i++) { - _PyInitError err = _Py_wstrlist_append(&config->nwarnoption, - &config->warnoptions, - options[i]); - if (_Py_INIT_FAILED(err)) { - return err; - } - } - return _Py_INIT_OK(); -} - - static _PyInitError config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) { - _PyInitError err; - - assert(config->nwarnoption == 0); + assert(config->warnoptions.length == 0); /* The priority order for warnings configuration is (highest precedence * first): @@ -1929,26 +1910,17 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) */ if (config->preconfig.dev_mode) { - err = _Py_wstrlist_append(&config->nwarnoption, - &config->warnoptions, - L"default"); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Append(&config->warnoptions, L"default")) { + return _Py_INIT_NO_MEMORY(); } } - err = config_add_warnings_optlist(config, - cmdline->nenv_warnoption, - cmdline->env_warnoptions); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Extend(&config->warnoptions, &cmdline->env_warnoptions) < 0) { + return _Py_INIT_NO_MEMORY(); } - err = config_add_warnings_optlist(config, - cmdline->nwarnoption, - cmdline->warnoptions); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Extend(&config->warnoptions, &cmdline->warnoptions) < 0) { + return _Py_INIT_NO_MEMORY(); } /* If the bytes_warning_flag isn't set, bytesobject.c and bytearrayobject.c @@ -1956,18 +1928,15 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) * case. */ if (config->bytes_warning) { - wchar_t *filter; + const wchar_t *filter; if (config->bytes_warning> 1) { filter = L"error::BytesWarning"; } else { filter = L"default::BytesWarning"; } - err = _Py_wstrlist_append(&config->nwarnoption, - &config->warnoptions, - filter); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Append(&config->warnoptions, filter)) { + return _Py_INIT_NO_MEMORY(); } } return _Py_INIT_OK(); @@ -1977,23 +1946,24 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) static _PyInitError config_init_argv(_PyCoreConfig *config, const _PyCmdline *cmdline) { - /* Copy argv to be able to modify it (to force -c/-m) */ - int argc = cmdline->args->argc - _PyOS_optind; - wchar_t **argv; + _PyWstrList wargv = _PyWstrList_INIT; - if (argc <= 0 || cmdline->argv == NULL) { + /* Copy argv to be able to modify it (to force -c/-m) */ + if (cmdline->argv.length <= _PyOS_optind) { /* Ensure at least one (empty) argument is seen */ - static wchar_t *empty_argv[1] = {L""}; - argc = 1; - argv = _Py_wstrlist_copy(1, empty_argv); + if (_PyWstrList_Append(&wargv, L"") < 0) { + return _Py_INIT_NO_MEMORY(); + } } else { - argv = _Py_wstrlist_copy(argc, &cmdline->argv[_PyOS_optind]); - } - - if (argv == NULL) { - return _Py_INIT_NO_MEMORY(); + _PyWstrList slice; + slice.length = cmdline->argv.length - _PyOS_optind; + slice.items = &cmdline->argv.items[_PyOS_optind]; + if (_PyWstrList_Copy(&wargv, &slice) < 0) { + return _Py_INIT_NO_MEMORY(); + } } + assert(wargv.length >= 1); wchar_t *arg0 = NULL; if (config->run_command != NULL) { @@ -2007,17 +1977,16 @@ config_init_argv(_PyCoreConfig *config, const _PyCmdline *cmdline) if (arg0 != NULL) { arg0 = _PyMem_RawWcsdup(arg0); if (arg0 == NULL) { - _Py_wstrlist_clear(argc, argv); + _PyWstrList_Clear(&wargv); return _Py_INIT_NO_MEMORY(); } - assert(argc >= 1); - PyMem_RawFree(argv[0]); - argv[0] = arg0; + PyMem_RawFree(wargv.items[0]); + wargv.items[0] = arg0; } - config->argc = argc; - config->argv = argv; + _PyWstrList_Clear(&config->argv); + config->argv = wargv; return _Py_INIT_OK(); } @@ -2097,7 +2066,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, return err; } - if (_Py_SetArgcArgv(cmdline->args->argc, cmdline->argv) < 0) { + if (_Py_SetArgcArgv(cmdline->argv.length, cmdline->argv.items) < 0) { return _Py_INIT_NO_MEMORY(); } return _Py_INIT_OK(); @@ -2117,9 +2086,8 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args, _PyCmdline cmdline; memset(&cmdline, 0, sizeof(cmdline)); - cmdline.args = args; - err = _PyArgv_Decode(cmdline.args, &cmdline.argv); + err = _PyArgv_AsWstrList(args, &cmdline.argv); if (_Py_INIT_FAILED(err)) { goto done; } diff --git a/Python/getopt.c b/Python/getopt.c index 1dc872041f..10bd1d49d7 100644 --- a/Python/getopt.c +++ b/Python/getopt.c @@ -37,9 +37,9 @@ extern "C" { #endif -int _PyOS_opterr = 1; /* generate error messages */ -int _PyOS_optind = 1; /* index into argv array */ -wchar_t *_PyOS_optarg = NULL; /* optional argument */ +int _PyOS_opterr = 1; /* generate error messages */ +Py_ssize_t _PyOS_optind = 1; /* index into argv array */ +const wchar_t *_PyOS_optarg = NULL; /* optional argument */ static wchar_t *opt_ptr = L""; @@ -61,7 +61,7 @@ void _PyOS_ResetGetOpt(void) opt_ptr = L""; } -int _PyOS_GetOpt(int argc, wchar_t **argv, int *longindex) +int _PyOS_GetOpt(Py_ssize_t argc, wchar_t **argv, int *longindex) { wchar_t *ptr; wchar_t option; diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 14dbba78af..fb2d19e279 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -154,14 +154,14 @@ _PyPathConfig_ClearGlobal(void) static wchar_t* -wstrlist_join(wchar_t sep, int count, wchar_t **list) +_PyWstrList_Join(const _PyWstrList *list, wchar_t sep) { size_t len = 1; /* NUL terminator */ - for (int i=0; i < count; i++) { + for (Py_ssize_t i=0; i < list->length; i++) { if (i != 0) { len++; } - len += wcslen(list[i]); + len += wcslen(list->items[i]); } wchar_t *text = PyMem_RawMalloc(len * sizeof(wchar_t)); @@ -169,8 +169,8 @@ wstrlist_join(wchar_t sep, int count, wchar_t **list) return NULL; } wchar_t *str = text; - for (int i=0; i < count; i++) { - wchar_t *path = list[i]; + for (Py_ssize_t i=0; i < list->length; i++) { + wchar_t *path = list->items[i]; if (i != 0) { *str++ = SEP; } @@ -194,9 +194,7 @@ _PyCoreConfig_SetPathConfig(const _PyCoreConfig *core_config) _PyInitError err; _PyPathConfig path_config = _PyPathConfig_INIT; - path_config.module_search_path = wstrlist_join(DELIM, - core_config->nmodule_search_path, - core_config->module_search_paths); + path_config.module_search_path = _PyWstrList_Join(&core_config->module_search_paths, DELIM); if (path_config.module_search_path == NULL) { goto no_memory; } @@ -244,10 +242,9 @@ static _PyInitError core_config_init_module_search_paths(_PyCoreConfig *config, _PyPathConfig *path_config) { - assert(config->module_search_paths == NULL); - assert(config->nmodule_search_path < 0); + assert(!config->use_module_search_paths); - config->nmodule_search_path = 0; + _PyWstrList_Clear(&config->module_search_paths); const wchar_t *sys_path = path_config->module_search_path; const wchar_t delim = DELIM; @@ -266,12 +263,10 @@ core_config_init_module_search_paths(_PyCoreConfig *config, memcpy(path, sys_path, path_len * sizeof(wchar_t)); path[path_len] = L'\0'; - _PyInitError err = _Py_wstrlist_append(&config->nmodule_search_path, - &config->module_search_paths, - path); + int res = _PyWstrList_Append(&config->module_search_paths, path); PyMem_RawFree(path); - if (_Py_INIT_FAILED(err)) { - return err; + if (res < 0) { + return _Py_INIT_NO_MEMORY(); } if (*p == '\0') { @@ -279,6 +274,7 @@ core_config_init_module_search_paths(_PyCoreConfig *config, } sys_path = p + 1; } + config->use_module_search_paths = 1; return _Py_INIT_OK(); } @@ -294,7 +290,7 @@ _PyCoreConfig_CalculatePathConfig(_PyCoreConfig *config) goto error; } - if (config->nmodule_search_path < 0) { + if (!config->use_module_search_paths) { err = core_config_init_module_search_paths(config, &path_config); if (_Py_INIT_FAILED(err)) { goto error; @@ -352,7 +348,7 @@ _PyInitError _PyCoreConfig_InitPathConfig(_PyCoreConfig *config) { /* Do we need to calculate the path? */ - if ((config->nmodule_search_path < 0) + if (!config->use_module_search_paths || (config->executable == NULL) || (config->prefix == NULL) #ifdef MS_WINDOWS @@ -567,8 +563,10 @@ Py_GetProgramName(void) /* Compute argv[0] which will be prepended to sys.argv */ PyObject* -_PyPathConfig_ComputeArgv0(int argc, wchar_t **argv) +_PyPathConfig_ComputeArgv0(const _PyWstrList *argv) { + assert(_PyWstrList_CheckConsistency(argv)); + wchar_t *argv0; wchar_t *p = NULL; Py_ssize_t n = 0; @@ -585,8 +583,8 @@ _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv) wchar_t fullpath[MAX_PATH]; #endif - argv0 = argv[0]; - if (argc > 0 && argv0 != NULL) { + if (argv->length > 0) { + argv0 = argv->items[0]; have_module_arg = (wcscmp(argv0, L"-m") == 0); have_script_arg = !have_module_arg && (wcscmp(argv0, L"-c") != 0); } diff --git a/Python/preconfig.c b/Python/preconfig.c index 50d66b1249..a86ece57cf 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -64,33 +64,38 @@ _Py_SetFileSystemEncoding(const char *encoding, const char *errors) /* --- _PyArgv ---------------------------------------------------- */ _PyInitError -_PyArgv_Decode(const _PyArgv *args, wchar_t*** argv_p) +_PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list) { - wchar_t** argv; + _PyWstrList wargv = _PyWstrList_INIT; if (args->use_bytes_argv) { - /* +1 for a the NULL terminator */ - size_t size = sizeof(wchar_t*) * (args->argc + 1); - argv = (wchar_t **)PyMem_RawMalloc(size); - if (argv == NULL) { + size_t size = sizeof(wchar_t*) * args->argc; + wargv.items = (wchar_t **)PyMem_RawMalloc(size); + if (wargv.items == NULL) { return _Py_INIT_NO_MEMORY(); } - for (int i = 0; i < args->argc; i++) { + for (Py_ssize_t i = 0; i < args->argc; i++) { size_t len; wchar_t *arg = Py_DecodeLocale(args->bytes_argv[i], &len); if (arg == NULL) { - _Py_wstrlist_clear(i, argv); + _PyWstrList_Clear(&wargv); return DECODE_LOCALE_ERR("command line arguments", (Py_ssize_t)len); } - argv[i] = arg; + wargv.items[i] = arg; + wargv.length++; } - argv[args->argc] = NULL; + + _PyWstrList_Clear(list); + *list = wargv; } else { - argv = args->wchar_argv; + wargv.length = args->argc; + wargv.items = args->wchar_argv; + if (_PyWstrList_Copy(list, &wargv) < 0) { + return _Py_INIT_NO_MEMORY(); + } } - *argv_p = argv; return _Py_INIT_OK(); } @@ -98,25 +103,16 @@ _PyArgv_Decode(const _PyArgv *args, wchar_t*** argv_p) /* --- _PyPreCmdline ------------------------------------------------- */ typedef struct { - const _PyArgv *args; - int argc; - wchar_t **argv; - int nxoption; /* Number of -X options */ - wchar_t **xoptions; /* -X options */ + _PyWstrList argv; + _PyWstrList xoptions; /* -X options */ } _PyPreCmdline; static void precmdline_clear(_PyPreCmdline *cmdline) { - if (cmdline->args->use_bytes_argv && cmdline->argv != NULL) { - _Py_wstrlist_clear(cmdline->args->argc, cmdline->argv); - } - cmdline->argv = NULL; - - _Py_wstrlist_clear(cmdline->nxoption, cmdline->xoptions); - cmdline->nxoption = 0; - cmdline->xoptions = NULL; + _PyWstrList_Clear(&cmdline->argv); + _PyWstrList_Clear(&cmdline->xoptions); } @@ -267,10 +263,10 @@ _Py_get_env_flag(_PyPreConfig *config, int *flag, const char *name) const wchar_t* -_Py_get_xoption(int nxoption, wchar_t * const *xoptions, const wchar_t *name) +_Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name) { - for (int i=0; i < nxoption; i++) { - const wchar_t *option = xoptions[i]; + for (Py_ssize_t i=0; i < xoptions->length; i++) { + const wchar_t *option = xoptions->items[i]; size_t len; wchar_t *sep = wcschr(option, L'='); if (sep != NULL) { @@ -292,7 +288,7 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) { const wchar_t *xopt; if (cmdline) { - xopt = _Py_get_xoption(cmdline->nxoption, cmdline->xoptions, L"utf8"); + xopt = _Py_get_xoption(&cmdline->xoptions, L"utf8"); } else { xopt = NULL; @@ -435,7 +431,7 @@ preconfig_read(_PyPreConfig *config, const _PyPreCmdline *cmdline) } /* dev_mode */ - if ((cmdline && _Py_get_xoption(cmdline->nxoption, cmdline->xoptions, L"dev")) + if ((cmdline && _Py_get_xoption(&cmdline->xoptions, L"dev")) || _PyPreConfig_GetEnv(config, "PYTHONDEVMODE")) { config->dev_mode = 1; @@ -579,7 +575,7 @@ preconfig_parse_cmdline(_PyPreConfig *config, _PyPreCmdline *cmdline) _PyOS_opterr = 0; do { int longindex = -1; - int c = _PyOS_GetOpt(cmdline->args->argc, cmdline->argv, &longindex); + int c = _PyOS_GetOpt(cmdline->argv.length, cmdline->argv.items, &longindex); if (c == EOF || c == 'c' || c == 'm') { break; @@ -596,12 +592,8 @@ preconfig_parse_cmdline(_PyPreConfig *config, _PyPreCmdline *cmdline) case 'X': { - _PyInitError err; - err = _Py_wstrlist_append(&cmdline->nxoption, - &cmdline->xoptions, - _PyOS_optarg); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) { + return _Py_INIT_NO_MEMORY(); } break; } @@ -624,9 +616,8 @@ preconfig_from_argv(_PyPreConfig *config, const _PyArgv *args) _PyPreCmdline cmdline; memset(&cmdline, 0, sizeof(cmdline)); - cmdline.args = args; - err = _PyArgv_Decode(cmdline.args, &cmdline.argv); + err = _PyArgv_AsWstrList(args, &cmdline.argv); if (_Py_INIT_FAILED(err)) { goto done; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 99fd460ff5..b3330a01f7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2739,35 +2739,35 @@ PySys_SetPath(const wchar_t *path) } static PyObject * -makeargvobject(int argc, wchar_t **argv) +make_sys_argv(int argc, wchar_t * const * argv) { - PyObject *av; - if (argc <= 0 || argv == NULL) { - /* Ensure at least one (empty) argument is seen */ - static wchar_t *empty_argv[1] = {L""}; - argv = empty_argv; - argc = 1; + PyObject *list = PyList_New(argc); + if (list == NULL) { + return NULL; } - av = PyList_New(argc); - if (av != NULL) { - int i; - for (i = 0; i < argc; i++) { - PyObject *v = PyUnicode_FromWideChar(argv[i], -1); - if (v == NULL) { - Py_DECREF(av); - av = NULL; - break; - } - PyList_SET_ITEM(av, i, v); + + for (Py_ssize_t i = 0; i < argc; i++) { + PyObject *v = PyUnicode_FromWideChar(argv[i], -1); + if (v == NULL) { + Py_DECREF(list); + return NULL; } + PyList_SET_ITEM(list, i, v); } - return av; + return list; } void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) { - PyObject *av = makeargvobject(argc, argv); + if (argc < 1 || argv == NULL) { + /* Ensure at least one (empty) argument is seen */ + wchar_t* empty_argv[1] = {L""}; + argv = empty_argv; + argc = 1; + } + + PyObject *av = make_sys_argv(argc, argv); if (av == NULL) { Py_FatalError("no mem for sys.argv"); } @@ -2780,7 +2780,8 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) if (updatepath) { /* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path. If argv[0] is a symlink, use the real path. */ - PyObject *argv0 = _PyPathConfig_ComputeArgv0(argc, argv); + const _PyWstrList argv_list = {.length = argc, .items = argv}; + PyObject *argv0 = _PyPathConfig_ComputeArgv0(&argv_list); if (argv0 == NULL) { Py_FatalError("can't compute path0 from argv"); } -- cgit v1.2.1 From 625997622b4736e9184bdd8bf1e22a7b51be1afc Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Mar 2019 16:03:23 +0100 Subject: bpo-36301: _PyCoreConfig_Read() ensures that argv is not empty (GH-12347) If argv is empty, add an empty string. --- Python/coreconfig.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 15107fa36c..0827376509 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1464,6 +1464,13 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) return err; } + if (config->argv.length < 1) { + /* Ensure at least one (empty) argument is seen */ + if (_PyWstrList_Append(&config->argv, L"") < 0) { + return _Py_INIT_NO_MEMORY(); + } + } + assert(config->preconfig.use_environment >= 0); assert(config->filesystem_encoding != NULL); assert(config->filesystem_errors != NULL); -- cgit v1.2.1 From e3f4070aee6f2d489416fdcafd51d6b04d661919 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Mar 2019 16:04:20 +0100 Subject: bpo-33608: Fix PyEval_InitThreads() warning (GH-12346) The function has no return value. Fix the following warning on Windows: python\ceval.c(180): warning C4098: 'PyEval_InitThreads': 'void' function returning a value --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index 373cde9a17..dd8826bf9c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -177,7 +177,7 @@ PyEval_InitThreads(void) _PyRuntime.ceval.pending.lock = PyThread_allocate_lock(); if (_PyRuntime.ceval.pending.lock == NULL) { - return Py_FatalError("Can't initialize threads for pending calls"); + Py_FatalError("Can't initialize threads for pending calls"); } } -- cgit v1.2.1 From 842a2f07f2f08a935ef470bfdaeef40f87490cfc Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 15 Mar 2019 15:47:51 -0600 Subject: bpo-33608: Deal with pending calls relative to runtime shutdown. (gh-12246) --- Python/ceval.c | 82 ++++++++++++++++++++++++++++++++++++++-------------- Python/pylifecycle.c | 7 ++++- 2 files changed, 67 insertions(+), 22 deletions(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index dd8826bf9c..d6a0b33595 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -330,31 +330,33 @@ _PyEval_SignalReceived(void) /* Push one item onto the queue while holding the lock. */ static int -_push_pending_call(int (*func)(void *), void *arg) +_push_pending_call(struct _pending_calls *pending, + int (*func)(void *), void *arg) { - int i = _PyRuntime.ceval.pending.last; + int i = pending->last; int j = (i + 1) % NPENDINGCALLS; - if (j == _PyRuntime.ceval.pending.first) { + if (j == pending->first) { return -1; /* Queue full */ } - _PyRuntime.ceval.pending.calls[i].func = func; - _PyRuntime.ceval.pending.calls[i].arg = arg; - _PyRuntime.ceval.pending.last = j; + pending->calls[i].func = func; + pending->calls[i].arg = arg; + pending->last = j; return 0; } /* Pop one item off the queue while holding the lock. */ static void -_pop_pending_call(int (**func)(void *), void **arg) +_pop_pending_call(struct _pending_calls *pending, + int (**func)(void *), void **arg) { - int i = _PyRuntime.ceval.pending.first; - if (i == _PyRuntime.ceval.pending.last) { + int i = pending->first; + if (i == pending->last) { return; /* Queue empty */ } - *func = _PyRuntime.ceval.pending.calls[i].func; - *arg = _PyRuntime.ceval.pending.calls[i].arg; - _PyRuntime.ceval.pending.first = (i + 1) % NPENDINGCALLS; + *func = pending->calls[i].func; + *arg = pending->calls[i].arg; + pending->first = (i + 1) % NPENDINGCALLS; } /* This implementation is thread-safe. It allows @@ -365,9 +367,23 @@ _pop_pending_call(int (**func)(void *), void **arg) int Py_AddPendingCall(int (*func)(void *), void *arg) { - PyThread_acquire_lock(_PyRuntime.ceval.pending.lock, WAIT_LOCK); - int result = _push_pending_call(func, arg); - PyThread_release_lock(_PyRuntime.ceval.pending.lock); + struct _pending_calls *pending = &_PyRuntime.ceval.pending; + + PyThread_acquire_lock(pending->lock, WAIT_LOCK); + if (pending->finishing) { + PyThread_release_lock(pending->lock); + + PyObject *exc, *val, *tb; + PyErr_Fetch(&exc, &val, &tb); + PyErr_SetString(PyExc_SystemError, + "Py_AddPendingCall: cannot add pending calls " + "(Python shutting down)"); + PyErr_Print(); + PyErr_Restore(exc, val, tb); + return -1; + } + int result = _push_pending_call(pending, func, arg); + PyThread_release_lock(pending->lock); /* signal main loop */ SIGNAL_PENDING_CALLS(); @@ -400,7 +416,7 @@ handle_signals(void) } static int -make_pending_calls(void) +make_pending_calls(struct _pending_calls* pending) { static int busy = 0; @@ -425,9 +441,9 @@ make_pending_calls(void) void *arg = NULL; /* pop one item off the queue while holding the lock */ - PyThread_acquire_lock(_PyRuntime.ceval.pending.lock, WAIT_LOCK); - _pop_pending_call(&func, &arg); - PyThread_release_lock(_PyRuntime.ceval.pending.lock); + PyThread_acquire_lock(pending->lock, WAIT_LOCK); + _pop_pending_call(pending, &func, &arg); + PyThread_release_lock(pending->lock); /* having released the lock, perform the callback */ if (func == NULL) { @@ -448,6 +464,30 @@ error: return res; } +void +_Py_FinishPendingCalls(void) +{ + struct _pending_calls *pending = &_PyRuntime.ceval.pending; + + assert(PyGILState_Check()); + + PyThread_acquire_lock(pending->lock, WAIT_LOCK); + pending->finishing = 1; + PyThread_release_lock(pending->lock); + + if (!_Py_atomic_load_relaxed(&(pending->calls_to_do))) { + return; + } + + if (make_pending_calls(pending) < 0) { + PyObject *exc, *val, *tb; + PyErr_Fetch(&exc, &val, &tb); + PyErr_BadInternalCall(); + _PyErr_ChainExceptions(exc, val, tb); + PyErr_Print(); + } +} + /* Py_MakePendingCalls() is a simple wrapper for the sake of backward-compatibility. */ int @@ -462,7 +502,7 @@ Py_MakePendingCalls(void) return res; } - res = make_pending_calls(); + res = make_pending_calls(&_PyRuntime.ceval.pending); if (res != 0) { return res; } @@ -1012,7 +1052,7 @@ main_loop: if (_Py_atomic_load_relaxed( &_PyRuntime.ceval.pending.calls_to_do)) { - if (make_pending_calls() != 0) { + if (make_pending_calls(&_PyRuntime.ceval.pending) != 0) { goto error; } } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 0902508429..c2d431c912 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1049,17 +1049,21 @@ Py_FinalizeEx(void) if (!_PyRuntime.initialized) return status; + // Wrap up existing "threading"-module-created, non-daemon threads. wait_for_thread_shutdown(); /* Get current thread state and interpreter pointer */ tstate = _PyThreadState_GET(); interp = tstate->interp; + // Make any remaining pending calls. + _Py_FinishPendingCalls(); + /* The interpreter is still entirely intact at this point, and the * exit funcs may be relying on that. In particular, if some thread * or exit func is still waiting to do an import, the import machinery * expects Py_IsInitialized() to return true. So don't say the - * interpreter is uninitialized until after the exit funcs have run. + * runtime is uninitialized until after the exit funcs have run. * Note that Threading.py uses an exit func to do a join on all the * threads created thru it, so this also protects pending imports in * the threads created via Threading. @@ -1462,6 +1466,7 @@ Py_EndInterpreter(PyThreadState *tstate) Py_FatalError("Py_EndInterpreter: thread still has a frame"); interp->finalizing = 1; + // Wrap up existing "threading"-module-created, non-daemon threads. wait_for_thread_shutdown(); call_py_exitfuncs(interp); -- cgit v1.2.1 From c11183cdcff6af13c4339fdcce84ab63f7930ddc Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 15 Mar 2019 16:35:46 -0600 Subject: bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as necessary). (gh-12359) --- Python/pystate.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Python') diff --git a/Python/pystate.c b/Python/pystate.c index 3978baa7af..cdf5a698cb 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -418,7 +418,7 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp) int64_t refcount = interp->id_refcount; PyThread_release_lock(interp->id_mutex); - if (refcount == 0) { + if (refcount == 0 && interp->requires_idref) { // XXX Using the "head" thread isn't strictly correct. PyThreadState *tstate = PyInterpreterState_ThreadHead(interp); // XXX Possible GILState issues? @@ -428,6 +428,18 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp) } } +int +_PyInterpreterState_RequiresIDRef(PyInterpreterState *interp) +{ + return interp->requires_idref; +} + +void +_PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required) +{ + interp->requires_idref = required ? 1 : 0; +} + _PyCoreConfig * _PyInterpreterState_GetCoreConfig(PyInterpreterState *interp) { @@ -440,6 +452,16 @@ _PyInterpreterState_GetMainConfig(PyInterpreterState *interp) return &interp->config; } +PyObject * +_PyInterpreterState_GetMainModule(PyInterpreterState *interp) +{ + if (interp->modules == NULL) { + PyErr_SetString(PyExc_RuntimeError, "interpreter not initialized"); + return NULL; + } + return PyMapping_GetItemString(interp->modules, "__main__"); +} + /* Default implementation for _PyThreadState_GetFrame */ static struct _frame * threadstate_getframe(PyThreadState *self) @@ -1392,7 +1414,7 @@ _register_xidata(PyTypeObject *cls, crossinterpdatafunc getdata) static void _register_builtins_for_crossinterpreter_data(void); int -_PyCrossInterpreterData_Register_Class(PyTypeObject *cls, +_PyCrossInterpreterData_RegisterClass(PyTypeObject *cls, crossinterpdatafunc getdata) { if (!PyType_Check(cls)) { -- cgit v1.2.1 From d2fdd1fedf6b9dc785cf5025b548a989faed089a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 15 Mar 2019 17:47:43 -0600 Subject: bpo-36124: Add PyInterpreterState.dict. (gh-12132) --- Python/pystate.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Python') diff --git a/Python/pystate.c b/Python/pystate.c index cdf5a698cb..6a2dc102ec 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -224,6 +224,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp) Py_CLEAR(interp->builtins_copy); Py_CLEAR(interp->importlib); Py_CLEAR(interp->import_func); + Py_CLEAR(interp->dict); #ifdef HAVE_FORK Py_CLEAR(interp->before_forkers); Py_CLEAR(interp->after_forkers_parent); @@ -462,6 +463,19 @@ _PyInterpreterState_GetMainModule(PyInterpreterState *interp) return PyMapping_GetItemString(interp->modules, "__main__"); } +PyObject * +PyInterpreterState_GetDict(PyInterpreterState *interp) +{ + if (interp->dict == NULL) { + interp->dict = PyDict_New(); + if (interp->dict == NULL) { + PyErr_Clear(); + } + } + /* Returning NULL means no per-interpreter dict is available. */ + return interp->dict; +} + /* Default implementation for _PyThreadState_GetFrame */ static struct _frame * threadstate_getframe(PyThreadState *self) -- cgit v1.2.1 From 1b0393d5b7842dcd9e933117d2d5404d15e2ad00 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 16 Mar 2019 19:45:00 +0200 Subject: bpo-36127: Fix compiler warning in _PyArg_UnpackKeywords(). (GH-12353) --- Python/getargs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/getargs.c b/Python/getargs.c index 693a29cced..e50f9b5f5c 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2422,7 +2422,7 @@ _PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs, } /* copy keyword args using kwtuple to drive process */ - for (i = Py_MAX(nargs, posonly); i < maxargs; i++) { + for (i = Py_MAX((int)nargs, posonly); i < maxargs; i++) { if (nkwargs) { keyword = PyTuple_GET_ITEM(kwtuple, i - posonly); if (kwargs != NULL) { -- cgit v1.2.1 From 0c9258a6d299e0484538ef8d4b23f30515283db2 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 18 Mar 2019 13:51:53 +0000 Subject: bpo-36332: Allow compile() to handle AST objects with assignment expressions (GH-12398) --- Python/ast.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Python') diff --git a/Python/ast.c b/Python/ast.c index 971b8ddc8c..e9154fecff 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -316,13 +316,14 @@ validate_expr(expr_ty exp, expr_context_ty ctx) return validate_exprs(exp->v.List.elts, ctx, 0); case Tuple_kind: return validate_exprs(exp->v.Tuple.elts, ctx, 0); + case NamedExpr_kind: + return validate_expr(exp->v.NamedExpr.value, Load); /* This last case doesn't have any checking. */ case Name_kind: return 1; - default: - PyErr_SetString(PyExc_SystemError, "unexpected expression"); - return 0; } + PyErr_SetString(PyExc_SystemError, "unexpected expression"); + return 0; } static int -- cgit v1.2.1 From 9e06d2b865beb62e54a4da39eb191f9fb8385282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Mon, 18 Mar 2019 17:10:29 +0100 Subject: bpo-36328: Fix compiler warning in Py_NewInterpreter() (GH-12381) --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index c2d431c912..49a2f18e49 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1434,7 +1434,7 @@ handle_error: PyThreadState * Py_NewInterpreter(void) { - PyThreadState *tstate; + PyThreadState *tstate = NULL; _PyInitError err = new_interpreter(&tstate); if (_Py_INIT_FAILED(err)) { _Py_ExitInitError(err); -- cgit v1.2.1 From 1be0d1135f5627d0525eab635cf2da441d9cbc08 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 18 Mar 2019 17:47:26 +0100 Subject: bpo-36352: Clarify fileutils.h documentation (GH-12406) The last parameter of _Py_wreadlink(), _Py_wrealpath() and _Py_wgetcwd() is a length, not a size: number of characters including the trailing NUL character. Enhance also documentation of error conditions. --- Python/fileutils.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'Python') diff --git a/Python/fileutils.c b/Python/fileutils.c index 75e015afae..0ac690a211 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1629,10 +1629,12 @@ _Py_write_noraise(int fd, const void *buf, size_t count) #ifdef HAVE_READLINK /* Read value of symbolic link. Encode the path to the locale encoding, decode - the result from the locale encoding. Return -1 on error. */ + the result from the locale encoding. + Return -1 on encoding error, on readlink() error, if the internal buffer is + too short, on decoding error, or if 'buf' is too short. */ int -_Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) +_Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t buflen) { char *cpath; char cbuf[MAXPATHLEN]; @@ -1659,12 +1661,13 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) errno = EINVAL; return -1; } - if (bufsiz <= r1) { + /* wbuf must have space to store the trailing NUL character */ + if (buflen <= r1) { PyMem_RawFree(wbuf); errno = EINVAL; return -1; } - wcsncpy(buf, wbuf, bufsiz); + wcsncpy(buf, wbuf, buflen); PyMem_RawFree(wbuf); return (int)r1; } @@ -1674,11 +1677,12 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) /* Return the canonicalized absolute pathname. Encode path to the locale encoding, decode the result from the locale encoding. - Return NULL on error. */ + Return NULL on encoding error, realpath() error, decoding error + or if 'resolved_path' is too short. */ wchar_t* _Py_wrealpath(const wchar_t *path, - wchar_t *resolved_path, size_t resolved_path_size) + wchar_t *resolved_path, size_t resolved_path_len) { char *cpath; char cresolved_path[MAXPATHLEN]; @@ -1700,12 +1704,13 @@ _Py_wrealpath(const wchar_t *path, errno = EINVAL; return NULL; } - if (resolved_path_size <= r) { + /* wresolved_path must have space to store the trailing NUL character */ + if (resolved_path_len <= r) { PyMem_RawFree(wresolved_path); errno = EINVAL; return NULL; } - wcsncpy(resolved_path, wresolved_path, resolved_path_size); + wcsncpy(resolved_path, wresolved_path, resolved_path_len); PyMem_RawFree(wresolved_path); return resolved_path; } @@ -1713,14 +1718,15 @@ _Py_wrealpath(const wchar_t *path, /* Get the current directory. size is the buffer size in wide characters including the null character. Decode the path from the locale encoding. - Return NULL on error. */ + Return NULL on getcwd() error, on decoding error, or if 'buf' is + too short. */ wchar_t* -_Py_wgetcwd(wchar_t *buf, size_t size) +_Py_wgetcwd(wchar_t *buf, size_t buflen) { #ifdef MS_WINDOWS - int isize = (int)Py_MIN(size, INT_MAX); - return _wgetcwd(buf, isize); + int ibuflen = (int)Py_MIN(buflen, INT_MAX); + return _wgetcwd(buf, ibuflen); #else char fname[MAXPATHLEN]; wchar_t *wname; @@ -1731,11 +1737,12 @@ _Py_wgetcwd(wchar_t *buf, size_t size) wname = Py_DecodeLocale(fname, &len); if (wname == NULL) return NULL; - if (size <= len) { + /* wname must have space to store the trailing NUL character */ + if (buflen <= len) { PyMem_RawFree(wname); return NULL; } - wcsncpy(buf, wname, size); + wcsncpy(buf, wname, buflen); PyMem_RawFree(wname); return buf; #endif -- cgit v1.2.1 From c183444f7e2640b054956474d71aae6e8d31a543 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 18 Mar 2019 22:24:28 +0100 Subject: bpo-36301: Fix Py_Main() memory leaks (GH-12420) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bpo-36301, bpo-36333: * Fix memory allocator used by _PyPathConfig_ClearGlobal(): force the default allocator. * _PyPreConfig_ReadFromArgv(): free init_ctype_locale memory. * pymain_main(): call pymain_free() on init error Co-Authored-By: Stéphane Wirtel --- Python/pathconfig.c | 5 +++++ Python/preconfig.c | 1 + 2 files changed, 6 insertions(+) (limited to 'Python') diff --git a/Python/pathconfig.c b/Python/pathconfig.c index fb2d19e279..0ee87c4252 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -149,7 +149,12 @@ done: void _PyPathConfig_ClearGlobal(void) { + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + _PyPathConfig_Clear(&_Py_path_config); + + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } diff --git a/Python/preconfig.c b/Python/preconfig.c index a86ece57cf..1efc7ee5c5 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -758,6 +758,7 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) done: if (init_ctype_locale != NULL) { setlocale(LC_CTYPE, init_ctype_locale); + PyMem_RawFree(init_ctype_locale); } _PyPreConfig_Clear(&save_config); Py_UTF8Mode = init_utf8_mode ; -- cgit v1.2.1 From 5f9cf23502febe0eb3bc02e45c7d2bfc79424757 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 01:46:25 +0100 Subject: bpo-36301: Error if decoding pybuilddir.txt fails (GH-12422) Python initialization now fails if decoding pybuilddir.txt configuration file fails at startup. _PyPathConfig_Calculate() now reports memory allocation failure and decoding error on decoding pybuilddir.txt content from UTF-8/surrogateescape. --- Python/pathconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 0ee87c4252..87db66b752 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -712,7 +712,7 @@ _Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key, continue; } - wchar_t *tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n); + wchar_t *tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n, NULL); if (tmpbuffer) { wchar_t * state; wchar_t * tok = WCSTOK(tmpbuffer, L" \t\r\n", &state); -- cgit v1.2.1 From faddaedd05ca81a9fed3f315e7bc8dcf455824a2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 02:58:14 +0100 Subject: bpo-36352: Avoid hardcoded MAXPATHLEN size in getpath.c (GH-12423) * Use Py_ARRAY_LENGTH() rather than hardcoded MAXPATHLEN in getpath.c. * Pass string length to functions modifying strings. --- Python/fileutils.c | 2 +- Python/pathconfig.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'Python') diff --git a/Python/fileutils.c b/Python/fileutils.c index 0ac690a211..b933874193 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1716,7 +1716,7 @@ _Py_wrealpath(const wchar_t *path, } #endif -/* Get the current directory. size is the buffer size in wide characters +/* Get the current directory. buflen is the buffer size in wide characters including the null character. Decode the path from the locale encoding. Return NULL on getcwd() error, on decoding error, or if 'buf' is diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 87db66b752..f1818eb307 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -578,8 +578,8 @@ _PyPathConfig_ComputeArgv0(const _PyWstrList *argv) int have_script_arg = 0; int have_module_arg = 0; #ifdef HAVE_READLINK - wchar_t link[MAXPATHLEN+1]; - wchar_t argv0copy[2*MAXPATHLEN+1]; + wchar_t link[MAXPATHLEN + 1]; + wchar_t argv0copy[2 * MAXPATHLEN + 1]; int nr = 0; #endif #if defined(HAVE_REALPATH) @@ -607,7 +607,7 @@ _PyPathConfig_ComputeArgv0(const _PyWstrList *argv) #ifdef HAVE_READLINK if (have_script_arg) - nr = _Py_wreadlink(argv0, link, MAXPATHLEN); + nr = _Py_wreadlink(argv0, link, Py_ARRAY_LENGTH(link)); if (nr > 0) { /* It's a symlink */ link[nr] = '\0'; @@ -692,11 +692,12 @@ _Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key, wchar_t *value, size_t value_size) { int result = 0; /* meaning not found */ - char buffer[MAXPATHLEN*2+1]; /* allow extra for key, '=', etc. */ + char buffer[MAXPATHLEN * 2 + 1]; /* allow extra for key, '=', etc. */ + buffer[Py_ARRAY_LENGTH(buffer)-1] = '\0'; fseek(env_file, 0, SEEK_SET); while (!feof(env_file)) { - char * p = fgets(buffer, MAXPATHLEN*2, env_file); + char * p = fgets(buffer, Py_ARRAY_LENGTH(buffer) - 1, env_file); if (p == NULL) { break; @@ -721,7 +722,8 @@ _Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key, if ((tok != NULL) && !wcscmp(tok, L"=")) { tok = WCSTOK(NULL, L"\r\n", &state); if (tok != NULL) { - wcsncpy(value, tok, MAXPATHLEN); + wcsncpy(value, tok, value_size - 1); + value[value_size - 1] = L'\0'; result = 1; PyMem_RawFree(tmpbuffer); break; -- cgit v1.2.1 From e130a07eb20c4b655d182d5d10d778c7584efe55 Mon Sep 17 00:00:00 2001 From: btharper Date: Tue, 19 Mar 2019 06:50:25 -0400 Subject: bpo-36356: Fix memory leak in _PyPreConfig_Read() (GH-12425) _PyPreConfig_Read() now free 'old_old' at exit. --- Python/preconfig.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python') diff --git a/Python/preconfig.c b/Python/preconfig.c index 1efc7ee5c5..b03436181c 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -514,6 +514,7 @@ _PyPreConfig_Read(_PyPreConfig *config) err = preconfig_read(config, NULL); setlocale(LC_CTYPE, old_loc); + PyMem_RawFree(old_loc); return err; } -- cgit v1.2.1 From 943395fab925a11ea90d078e771cdfc4443e8c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Tue, 19 Mar 2019 11:51:32 +0100 Subject: bpo-36333: Fix leak _PyRuntimeState_Fini (GH-12400) --- Python/pystate.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Python') diff --git a/Python/pystate.c b/Python/pystate.c index 6a2dc102ec..36566b7671 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -92,6 +92,11 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime) runtime->interpreters.mutex = NULL; } + if (runtime->xidregistry.mutex != NULL) { + PyThread_free_lock(runtime->xidregistry.mutex); + runtime->xidregistry.mutex = NULL; + } + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } -- cgit v1.2.1 From a712679a2bffffefaacdc05f788d6ea50f72a561 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 14:19:38 +0100 Subject: bpo-36333, bpo-36356: Fix _PyEval_FiniThreads() (GH-12432) _PyEval_FiniThreads() now free the pending lock. --- Python/ceval.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index d6a0b33595..40320bf357 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -169,8 +169,10 @@ PyEval_ThreadsInitialized(void) void PyEval_InitThreads(void) { - if (gil_created()) + if (gil_created()) { return; + } + PyThread_init_thread(); create_gil(); take_gil(_PyThreadState_GET()); @@ -184,10 +186,17 @@ PyEval_InitThreads(void) void _PyEval_FiniThreads(void) { - if (!gil_created()) + if (!gil_created()) { return; + } + destroy_gil(); assert(!gil_created()); + + if (_PyRuntime.ceval.pending.lock != NULL) { + PyThread_free_lock(_PyRuntime.ceval.pending.lock); + _PyRuntime.ceval.pending.lock = NULL; + } } void -- cgit v1.2.1 From dcf617152e1d4c4a5e7965733928858a9c0936ca Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 16:09:27 +0100 Subject: bpo-36236: Handle removed cwd at Python init (GH-12424) At Python initialization, the current directory is no longer prepended to sys.path if it has been removed. Rename _PyPathConfig_ComputeArgv0() to _PyPathConfig_ComputeSysPath0() to avoid confusion between argv[0] and sys.path[0]. --- Python/pathconfig.c | 31 +++++++++++++++++++++++-------- Python/sysmodule.c | 22 ++++++++++++---------- 2 files changed, 35 insertions(+), 18 deletions(-) (limited to 'Python') diff --git a/Python/pathconfig.c b/Python/pathconfig.c index f1818eb307..743e1cd1ac 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -566,9 +566,18 @@ Py_GetProgramName(void) return _Py_path_config.program_name; } -/* Compute argv[0] which will be prepended to sys.argv */ -PyObject* -_PyPathConfig_ComputeArgv0(const _PyWstrList *argv) +/* Compute module search path from argv[0] or the current working + directory ("-m module" case) which will be prepended to sys.argv: + sys.path[0]. + + Return 1 if the path is correctly resolved, but *path0_p can be NULL + if the Unicode object fail to be created. + + Return 0 if it fails to resolve the full path (and *path0_p will be NULL), + for example if the current working directory has been removed (bpo-36236). + */ +int +_PyPathConfig_ComputeSysPath0(const _PyWstrList *argv, PyObject **path0_p) { assert(_PyWstrList_CheckConsistency(argv)); @@ -588,6 +597,8 @@ _PyPathConfig_ComputeArgv0(const _PyWstrList *argv) wchar_t fullpath[MAX_PATH]; #endif + assert(*path0_p == NULL); + if (argv->length > 0) { argv0 = argv->items[0]; have_module_arg = (wcscmp(argv0, L"-m") == 0); @@ -595,14 +606,17 @@ _PyPathConfig_ComputeArgv0(const _PyWstrList *argv) } if (have_module_arg) { - #if defined(HAVE_REALPATH) || defined(MS_WINDOWS) - _Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath)); +#if defined(HAVE_REALPATH) || defined(MS_WINDOWS) + if (!_Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath))) { + *path0_p = NULL; + return 0; + } argv0 = fullpath; n = wcslen(argv0); - #else +#else argv0 = L"."; n = 1; - #endif +#endif } #ifdef HAVE_READLINK @@ -675,7 +689,8 @@ _PyPathConfig_ComputeArgv0(const _PyWstrList *argv) } #endif /* All others */ - return PyUnicode_FromWideChar(argv0, n); + *path0_p = PyUnicode_FromWideChar(argv0, n); + return 1; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b3330a01f7..4351a7fb37 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2781,19 +2781,21 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) /* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path. If argv[0] is a symlink, use the real path. */ const _PyWstrList argv_list = {.length = argc, .items = argv}; - PyObject *argv0 = _PyPathConfig_ComputeArgv0(&argv_list); - if (argv0 == NULL) { - Py_FatalError("can't compute path0 from argv"); - } + PyObject *path0 = NULL; + if (_PyPathConfig_ComputeSysPath0(&argv_list, &path0)) { + if (path0 == NULL) { + Py_FatalError("can't compute path0 from argv"); + } - PyObject *sys_path = _PySys_GetObjectId(&PyId_path); - if (sys_path != NULL) { - if (PyList_Insert(sys_path, 0, argv0) < 0) { - Py_DECREF(argv0); - Py_FatalError("can't prepend path0 to sys.path"); + PyObject *sys_path = _PySys_GetObjectId(&PyId_path); + if (sys_path != NULL) { + if (PyList_Insert(sys_path, 0, path0) < 0) { + Py_DECREF(path0); + Py_FatalError("can't prepend path0 to sys.path"); + } } + Py_DECREF(path0); } - Py_DECREF(argv0); } } -- cgit v1.2.1 From fc96e5474a7bda1c5dec66420e4467fc9f7ca968 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 18:22:55 +0100 Subject: bpo-36236: Fix _PyPathConfig_ComputeSysPath0() for empty argv (GH-12441) * _PyPathConfig_ComputeSysPath0() now returns 0 if argv is empty. * Cleanup also _PyPathConfig_ComputeSysPath0() code: move variables definitions closer to where they are used. --- Python/pathconfig.c | 118 ++++++++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 55 deletions(-) (limited to 'Python') diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 743e1cd1ac..0ccb898e42 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -573,79 +573,84 @@ Py_GetProgramName(void) Return 1 if the path is correctly resolved, but *path0_p can be NULL if the Unicode object fail to be created. - Return 0 if it fails to resolve the full path (and *path0_p will be NULL), - for example if the current working directory has been removed (bpo-36236). + Return 0 if it fails to resolve the full path (and *path0_p will be NULL). + For example, return 0 if the current working directory has been removed + (bpo-36236) or if argv is empty. */ int _PyPathConfig_ComputeSysPath0(const _PyWstrList *argv, PyObject **path0_p) { assert(_PyWstrList_CheckConsistency(argv)); + assert(*path0_p == NULL); - wchar_t *argv0; - wchar_t *p = NULL; + if (argv->length == 0) { + /* Leave sys.path unchanged if sys.argv is empty */ + return 0; + } + + wchar_t *argv0 = argv->items[0]; + int have_module_arg = (wcscmp(argv0, L"-m") == 0); + int have_script_arg = (!have_module_arg && (wcscmp(argv0, L"-c") != 0)); + + wchar_t *path0 = argv0; Py_ssize_t n = 0; - int have_script_arg = 0; - int have_module_arg = 0; -#ifdef HAVE_READLINK - wchar_t link[MAXPATHLEN + 1]; - wchar_t argv0copy[2 * MAXPATHLEN + 1]; - int nr = 0; -#endif -#if defined(HAVE_REALPATH) + +#ifdef HAVE_REALPATH wchar_t fullpath[MAXPATHLEN]; #elif defined(MS_WINDOWS) wchar_t fullpath[MAX_PATH]; #endif - assert(*path0_p == NULL); - - if (argv->length > 0) { - argv0 = argv->items[0]; - have_module_arg = (wcscmp(argv0, L"-m") == 0); - have_script_arg = !have_module_arg && (wcscmp(argv0, L"-c") != 0); - } - if (have_module_arg) { #if defined(HAVE_REALPATH) || defined(MS_WINDOWS) - if (!_Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath))) { - *path0_p = NULL; - return 0; - } - argv0 = fullpath; - n = wcslen(argv0); + if (!_Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath))) { + return 0; + } + path0 = fullpath; #else - argv0 = L"."; - n = 1; + path0 = L"."; #endif + n = wcslen(path0); } #ifdef HAVE_READLINK - if (have_script_arg) - nr = _Py_wreadlink(argv0, link, Py_ARRAY_LENGTH(link)); + wchar_t link[MAXPATHLEN + 1]; + int nr = 0; + + if (have_script_arg) { + nr = _Py_wreadlink(path0, link, Py_ARRAY_LENGTH(link)); + } if (nr > 0) { /* It's a symlink */ link[nr] = '\0'; - if (link[0] == SEP) - argv0 = link; /* Link to absolute path */ - else if (wcschr(link, SEP) == NULL) - ; /* Link without path */ + if (link[0] == SEP) { + path0 = link; /* Link to absolute path */ + } + else if (wcschr(link, SEP) == NULL) { + /* Link without path */ + } else { - /* Must join(dirname(argv0), link) */ - wchar_t *q = wcsrchr(argv0, SEP); - if (q == NULL) - argv0 = link; /* argv0 without path */ + /* Must join(dirname(path0), link) */ + wchar_t *q = wcsrchr(path0, SEP); + if (q == NULL) { + /* path0 without path */ + path0 = link; + } else { - /* Must make a copy, argv0copy has room for 2 * MAXPATHLEN */ - wcsncpy(argv0copy, argv0, MAXPATHLEN); - q = wcsrchr(argv0copy, SEP); + /* Must make a copy, path0copy has room for 2 * MAXPATHLEN */ + wchar_t path0copy[2 * MAXPATHLEN + 1]; + wcsncpy(path0copy, path0, MAXPATHLEN); + q = wcsrchr(path0copy, SEP); wcsncpy(q+1, link, MAXPATHLEN); q[MAXPATHLEN + 1] = L'\0'; - argv0 = argv0copy; + path0 = path0copy; } } } #endif /* HAVE_READLINK */ + wchar_t *p = NULL; + #if SEP == '\\' /* Special case for Microsoft filename syntax */ if (have_script_arg) { @@ -653,43 +658,46 @@ _PyPathConfig_ComputeSysPath0(const _PyWstrList *argv, PyObject **path0_p) #if defined(MS_WINDOWS) /* Replace the first element in argv with the full path. */ wchar_t *ptemp; - if (GetFullPathNameW(argv0, + if (GetFullPathNameW(path0, Py_ARRAY_LENGTH(fullpath), fullpath, &ptemp)) { - argv0 = fullpath; + path0 = fullpath; } #endif - p = wcsrchr(argv0, SEP); + p = wcsrchr(path0, SEP); /* Test for alternate separator */ - q = wcsrchr(p ? p : argv0, '/'); + q = wcsrchr(p ? p : path0, '/'); if (q != NULL) p = q; if (p != NULL) { - n = p + 1 - argv0; + n = p + 1 - path0; if (n > 1 && p[-1] != ':') n--; /* Drop trailing separator */ } } -#else /* All other filename syntaxes */ +#else + /* All other filename syntaxes */ if (have_script_arg) { #if defined(HAVE_REALPATH) - if (_Py_wrealpath(argv0, fullpath, Py_ARRAY_LENGTH(fullpath))) { - argv0 = fullpath; + if (_Py_wrealpath(path0, fullpath, Py_ARRAY_LENGTH(fullpath))) { + path0 = fullpath; } #endif - p = wcsrchr(argv0, SEP); + p = wcsrchr(path0, SEP); } if (p != NULL) { - n = p + 1 - argv0; + n = p + 1 - path0; #if SEP == '/' /* Special case for Unix filename syntax */ - if (n > 1) - n--; /* Drop trailing separator */ + if (n > 1) { + /* Drop trailing separator */ + n--; + } #endif /* Unix */ } #endif /* All others */ - *path0_p = PyUnicode_FromWideChar(argv0, n); + *path0_p = PyUnicode_FromWideChar(path0, n); return 1; } -- cgit v1.2.1 From fd23cfa464ab93273370475900819c1ea37c852f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Mar 2019 00:03:01 +0100 Subject: bpo-35388: Fix _PyRuntime_Finalize() (GH-12443) Calling _PyRuntime_Initialize() after _PyRuntime_Finalize() now re-initializes _PyRuntime structure. Previously, _PyRuntime_Initialize() did nothing in that case. --- Python/pylifecycle.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Python') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 49a2f18e49..df9570b2e4 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -69,6 +69,7 @@ static void call_ll_exitfuncs(void); int _Py_UnhandledKeyboardInterrupt = 0; _PyRuntimeState _PyRuntime = _PyRuntimeState_INIT; +static int runtime_initialized = 0; _PyInitError _PyRuntime_Initialize(void) @@ -79,11 +80,10 @@ _PyRuntime_Initialize(void) every Py_Initialize() call, but doing so breaks the runtime. This is because the runtime state is not properly finalized currently. */ - static int initialized = 0; - if (initialized) { + if (runtime_initialized) { return _Py_INIT_OK(); } - initialized = 1; + runtime_initialized = 1; return _PyRuntimeState_Init(&_PyRuntime); } @@ -92,6 +92,7 @@ void _PyRuntime_Finalize(void) { _PyRuntimeState_Fini(&_PyRuntime); + runtime_initialized = 0; } int -- cgit v1.2.1 From 0d765e3849f1010276bb349b557b79ed94befa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Wed, 20 Mar 2019 00:37:20 +0100 Subject: bpo-36362: Avoid unused variables when HAVE_DYNAMIC_LOADING is not defined (GH-12430) https://bugs.python.org/issue36362 --- Python/import.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Python') diff --git a/Python/import.c b/Python/import.c index 898321ac3b..bf3a99414f 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1983,13 +1983,14 @@ _imp_extension_suffixes_impl(PyObject *module) /*[clinic end generated code: output=0bf346e25a8f0cd3 input=ecdeeecfcb6f839e]*/ { PyObject *list; - const char *suffix; - unsigned int index = 0; list = PyList_New(0); if (list == NULL) return NULL; #ifdef HAVE_DYNAMIC_LOADING + const char *suffix; + unsigned int index = 0; + while ((suffix = _PyImport_DynLoadFiletab[index])) { PyObject *item = PyUnicode_FromString(suffix); if (item == NULL) { -- cgit v1.2.1 From f29084d611a6ca504c99a0967371374febf0ccc3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Mar 2019 02:20:13 +0100 Subject: bpo-36301: Add _PyRuntime.pre_initialized (GH-12457) * Add _PyRuntime.pre_initialized: set to 1 when Python is pre-initialized * Add _Py_PreInitialize() and _Py_PreInitializeFromPreConfig(). * _PyCoreConfig_Read() now calls _Py_PreInitialize(). * Move _PyPreConfig_GetGlobalConfig() and _PyCoreConfig_GetGlobalConfig() calls from main.c to preconfig.c and coreconfig.c. --- Python/coreconfig.c | 7 +++++++ Python/preconfig.c | 2 ++ Python/pylifecycle.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 4 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 0827376509..de2058c0f3 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1367,6 +1367,11 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) { _PyInitError err; + err = _Py_PreInitialize(); + if (_Py_INIT_FAILED(err)) { + return err; + } + _PyCoreConfig_GetGlobalConfig(config); if (preconfig != NULL) { @@ -2025,6 +2030,8 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, int need_usage = 0; _PyInitError err; + _PyCoreConfig_GetGlobalConfig(config); + err = config_init_program(config, cmdline); if (_Py_INIT_FAILED(err)) { return err; diff --git a/Python/preconfig.c b/Python/preconfig.c index b03436181c..a149ea54f6 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -672,6 +672,8 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) goto done; } + _PyPreConfig_GetGlobalConfig(config); + if (_PyPreConfig_Copy(&save_config, config) < 0) { err = _Py_INIT_NO_MEMORY(); goto done; diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index df9570b2e4..994a94f140 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -714,19 +714,57 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, } +_PyInitError +_Py_PreInitializeFromPreConfig(_PyPreConfig *config) +{ + if (config != NULL) { + _PyInitError err = _PyPreConfig_Write(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + } + + _PyRuntime.pre_initialized = 1; + return _Py_INIT_OK(); +} + + static _PyInitError -pyinit_preconfig(_PyPreConfig *preconfig, const _PyPreConfig *src_preconfig) +pyinit_preconfig(_PyPreConfig *config, const _PyPreConfig *src_config) { - if (_PyPreConfig_Copy(preconfig, src_preconfig) < 0) { + _PyInitError err; + + err = _PyRuntime_Initialize(); + if (_Py_INIT_FAILED(err)) { + return err; + } + + if (_PyPreConfig_Copy(config, src_config) < 0) { return _Py_INIT_ERR("failed to copy pre config"); } - _PyInitError err = _PyPreConfig_Read(preconfig); + err = _PyPreConfig_Read(config); if (_Py_INIT_FAILED(err)) { return err; } - return _PyPreConfig_Write(preconfig); + return _Py_PreInitializeFromPreConfig(config); +} + + +_PyInitError +_Py_PreInitialize(void) +{ + _PyInitError err = _PyRuntime_Initialize(); + if (_Py_INIT_FAILED(err)) { + return err; + } + + if (_PyRuntime.pre_initialized) { + return _Py_INIT_OK(); + } + + return _Py_PreInitializeFromPreConfig(NULL); } -- cgit v1.2.1 From 4a1468e593c4b67d8c78b78070fff9e18ec5d790 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Mar 2019 03:11:38 +0100 Subject: bpo-36356: Fix _PyCoreConfig_Read() (GH-12454) Don't override parameters which are already set by the user. --- Python/coreconfig.c | 55 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index de2058c0f3..e1d883c51c 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -961,13 +961,15 @@ config_read_env_vars(_PyCoreConfig *config) config->malloc_stats = 1; } - wchar_t *path; - int res = _PyCoreConfig_GetEnvDup(config, &path, - L"PYTHONPATH", "PYTHONPATH"); - if (res < 0) { - return DECODE_LOCALE_ERR("PYTHONPATH", res); + if (config->module_search_path_env == NULL) { + wchar_t *path; + int res = _PyCoreConfig_GetEnvDup(config, &path, + L"PYTHONPATH", "PYTHONPATH"); + if (res < 0) { + return DECODE_LOCALE_ERR("PYTHONPATH", res); + } + config->module_search_path_env = path; } - config->module_search_path_env = path; if (config->use_hash_seed < 0) { _PyInitError err = config_init_hash_seed(config); @@ -1689,18 +1691,20 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, } if (c == 'c') { - /* -c is the last option; following arguments - that look like options are left for the - command to interpret. */ - size_t len = wcslen(_PyOS_optarg) + 1 + 1; - wchar_t *command = PyMem_RawMalloc(sizeof(wchar_t) * len); - if (command == NULL) { - return _Py_INIT_NO_MEMORY(); + if (config->run_command == NULL) { + /* -c is the last option; following arguments + that look like options are left for the + command to interpret. */ + size_t len = wcslen(_PyOS_optarg) + 1 + 1; + wchar_t *command = PyMem_RawMalloc(sizeof(wchar_t) * len); + if (command == NULL) { + return _Py_INIT_NO_MEMORY(); + } + memcpy(command, _PyOS_optarg, (len - 2) * sizeof(wchar_t)); + command[len - 2] = '\n'; + command[len - 1] = 0; + config->run_command = command; } - memcpy(command, _PyOS_optarg, (len - 2) * sizeof(wchar_t)); - command[len - 2] = '\n'; - command[len - 1] = 0; - config->run_command = command; break; } @@ -1708,9 +1712,11 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, /* -m is the last option; following arguments that look like options are left for the module to interpret. */ - config->run_module = _PyMem_RawWcsdup(_PyOS_optarg); if (config->run_module == NULL) { - return _Py_INIT_NO_MEMORY(); + config->run_module = _PyMem_RawWcsdup(_PyOS_optarg); + if (config->run_module == NULL) { + return _Py_INIT_NO_MEMORY(); + } } break; } @@ -1825,7 +1831,8 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, if (config->run_command == NULL && config->run_module == NULL && _PyOS_optind < cmdline->argv.length - && wcscmp(cmdline->argv.items[_PyOS_optind], L"-") != 0) + && wcscmp(cmdline->argv.items[_PyOS_optind], L"-") != 0 + && config->run_filename == NULL) { config->run_filename = _PyMem_RawWcsdup(cmdline->argv.items[_PyOS_optind]); if (config->run_filename == NULL) { @@ -2032,9 +2039,11 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, _PyCoreConfig_GetGlobalConfig(config); - err = config_init_program(config, cmdline); - if (_Py_INIT_FAILED(err)) { - return err; + if (config->program == NULL) { + err = config_init_program(config, cmdline); + if (_Py_INIT_FAILED(err)) { + return err; + } } err = config_parse_cmdline(config, cmdline, &need_usage); -- cgit v1.2.1 From fa1537684869186da7938e4330361bf02363bac8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Mar 2019 04:25:38 +0100 Subject: bpo-36301: Add _PyPreCmdline internal API (GH-12458) _PyCoreConfig_ReadFromArgv() now reuses the code parsing command line options from preconfig.c. --- Python/coreconfig.c | 67 ++++++++++++++++++++++++++++++----------------------- Python/preconfig.c | 55 +++++++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 47 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index e1d883c51c..1881f00bf2 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1658,7 +1658,7 @@ fail: /* --- _PyCmdline ------------------------------------------------- */ typedef struct { - _PyWstrList argv; + _PyPreCmdline precmdline; _PyWstrList warnoptions; /* Command line -W options */ _PyWstrList env_warnoptions; /* PYTHONWARNINGS environment variables */ int print_help; /* -h, -? options */ @@ -1669,9 +1669,9 @@ typedef struct { static void cmdline_clear(_PyCmdline *cmdline) { + _PyPreCmdline_Clear(&cmdline->precmdline); _PyWstrList_Clear(&cmdline->warnoptions); _PyWstrList_Clear(&cmdline->env_warnoptions); - _PyWstrList_Clear(&cmdline->argv); } @@ -1682,10 +1682,12 @@ static _PyInitError config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, int *need_usage) { + const _PyWstrList *argv = &cmdline->precmdline.argv; + _PyOS_ResetGetOpt(); do { int longindex = -1; - int c = _PyOS_GetOpt(cmdline->argv.length, cmdline->argv.items, &longindex); + int c = _PyOS_GetOpt(argv->length, argv->items, &longindex); if (c == EOF) { break; } @@ -1754,6 +1756,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, case 'E': case 'I': + case 'X': /* option handled by _PyPreConfig_ReadFromArgv() */ break; @@ -1806,12 +1809,6 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, } break; - case 'X': - if (_PyWstrList_Append(&config->xoptions, _PyOS_optarg) < 0) { - return _Py_INIT_NO_MEMORY(); - } - break; - case 'q': config->quiet++; break; @@ -1830,11 +1827,11 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, } while (1); if (config->run_command == NULL && config->run_module == NULL - && _PyOS_optind < cmdline->argv.length - && wcscmp(cmdline->argv.items[_PyOS_optind], L"-") != 0 + && _PyOS_optind < argv->length + && wcscmp(argv->items[_PyOS_optind], L"-") != 0 && config->run_filename == NULL) { - config->run_filename = _PyMem_RawWcsdup(cmdline->argv.items[_PyOS_optind]); + config->run_filename = _PyMem_RawWcsdup(argv->items[_PyOS_optind]); if (config->run_filename == NULL) { return _Py_INIT_NO_MEMORY(); } @@ -1892,9 +1889,10 @@ cmdline_init_env_warnoptions(_PyCmdline *cmdline, const _PyCoreConfig *config) static _PyInitError config_init_program(_PyCoreConfig *config, const _PyCmdline *cmdline) { + const _PyWstrList *argv = &cmdline->precmdline.argv; wchar_t *program; - if (cmdline->argv.length >= 1) { - program = cmdline->argv.items[0]; + if (argv->length >= 1) { + program = argv->items[0]; } else { program = L""; @@ -1965,24 +1963,25 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) static _PyInitError config_init_argv(_PyCoreConfig *config, const _PyCmdline *cmdline) { - _PyWstrList wargv = _PyWstrList_INIT; + const _PyWstrList *cmdline_argv = &cmdline->precmdline.argv; + _PyWstrList config_argv = _PyWstrList_INIT; /* Copy argv to be able to modify it (to force -c/-m) */ - if (cmdline->argv.length <= _PyOS_optind) { + if (cmdline_argv->length <= _PyOS_optind) { /* Ensure at least one (empty) argument is seen */ - if (_PyWstrList_Append(&wargv, L"") < 0) { + if (_PyWstrList_Append(&config_argv, L"") < 0) { return _Py_INIT_NO_MEMORY(); } } else { _PyWstrList slice; - slice.length = cmdline->argv.length - _PyOS_optind; - slice.items = &cmdline->argv.items[_PyOS_optind]; - if (_PyWstrList_Copy(&wargv, &slice) < 0) { + slice.length = cmdline_argv->length - _PyOS_optind; + slice.items = &cmdline_argv->items[_PyOS_optind]; + if (_PyWstrList_Copy(&config_argv, &slice) < 0) { return _Py_INIT_NO_MEMORY(); } } - assert(wargv.length >= 1); + assert(config_argv.length >= 1); wchar_t *arg0 = NULL; if (config->run_command != NULL) { @@ -1996,16 +1995,16 @@ config_init_argv(_PyCoreConfig *config, const _PyCmdline *cmdline) if (arg0 != NULL) { arg0 = _PyMem_RawWcsdup(arg0); if (arg0 == NULL) { - _PyWstrList_Clear(&wargv); + _PyWstrList_Clear(&config_argv); return _Py_INIT_NO_MEMORY(); } - PyMem_RawFree(wargv.items[0]); - wargv.items[0] = arg0; + PyMem_RawFree(config_argv.items[0]); + config_argv.items[0] = arg0; } _PyWstrList_Clear(&config->argv); - config->argv = wargv; + config->argv = config_argv; return _Py_INIT_OK(); } @@ -2046,6 +2045,16 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, } } + err = _PyPreCmdline_Read(&cmdline->precmdline); + if (_Py_INIT_FAILED(err)) { + return err; + } + + _PyPreCmdline_SetPreConfig(&cmdline->precmdline, &config->preconfig); + if (_PyWstrList_Extend(&config->xoptions, &cmdline->precmdline.xoptions) < 0) { + return _Py_INIT_NO_MEMORY(); + } + err = config_parse_cmdline(config, cmdline, &need_usage); if (_Py_INIT_FAILED(err)) { return err; @@ -2089,7 +2098,8 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, return err; } - if (_Py_SetArgcArgv(cmdline->argv.length, cmdline->argv.items) < 0) { + const _PyWstrList *argv = &cmdline->precmdline.argv; + if (_Py_SetArgcArgv(argv->length, argv->items) < 0) { return _Py_INIT_NO_MEMORY(); } return _Py_INIT_OK(); @@ -2107,10 +2117,9 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args, { _PyInitError err; - _PyCmdline cmdline; - memset(&cmdline, 0, sizeof(cmdline)); + _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT}; - err = _PyArgv_AsWstrList(args, &cmdline.argv); + err = _PyPreCmdline_Init(&cmdline.precmdline, args); if (_Py_INIT_FAILED(err)) { goto done; } diff --git a/Python/preconfig.c b/Python/preconfig.c index a149ea54f6..d856c124f3 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -102,20 +102,21 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list) /* --- _PyPreCmdline ------------------------------------------------- */ -typedef struct { - _PyWstrList argv; - _PyWstrList xoptions; /* -X options */ -} _PyPreCmdline; - - -static void -precmdline_clear(_PyPreCmdline *cmdline) +void +_PyPreCmdline_Clear(_PyPreCmdline *cmdline) { _PyWstrList_Clear(&cmdline->argv); _PyWstrList_Clear(&cmdline->xoptions); } +_PyInitError +_PyPreCmdline_Init(_PyPreCmdline *cmdline, const _PyArgv *args) +{ + return _PyArgv_AsWstrList(args, &cmdline->argv); +} + + /* --- _PyPreConfig ----------------------------------------------- */ void @@ -520,6 +521,21 @@ _PyPreConfig_Read(_PyPreConfig *config) } +void +_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (cmdline->ATTR != -1) { \ + config->ATTR = cmdline->ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + +#undef COPY_ATTR +} + + int _PyPreConfig_AsDict(const _PyPreConfig *config, PyObject *dict) { @@ -567,16 +583,18 @@ fail: /* Parse the command line arguments */ -static _PyInitError -preconfig_parse_cmdline(_PyPreConfig *config, _PyPreCmdline *cmdline) +_PyInitError +_PyPreCmdline_Read(_PyPreCmdline *cmdline) { + _PyWstrList *argv = &cmdline->argv; + _PyOS_ResetGetOpt(); /* Don't log parsing errors into stderr here: _PyCoreConfig_ReadFromArgv() is responsible for that */ _PyOS_opterr = 0; do { int longindex = -1; - int c = _PyOS_GetOpt(cmdline->argv.length, cmdline->argv.items, &longindex); + int c = _PyOS_GetOpt(argv->length, argv->items, &longindex); if (c == EOF || c == 'c' || c == 'm') { break; @@ -584,11 +602,11 @@ preconfig_parse_cmdline(_PyPreConfig *config, _PyPreCmdline *cmdline) switch (c) { case 'E': - config->use_environment = 0; + cmdline->use_environment = 0; break; case 'I': - config->isolated++; + cmdline->isolated = 1; break; case 'X': @@ -615,19 +633,20 @@ preconfig_from_argv(_PyPreConfig *config, const _PyArgv *args) { _PyInitError err; - _PyPreCmdline cmdline; - memset(&cmdline, 0, sizeof(cmdline)); + _PyPreCmdline cmdline = _PyPreCmdline_INIT; - err = _PyArgv_AsWstrList(args, &cmdline.argv); + err = _PyPreCmdline_Init(&cmdline, args); if (_Py_INIT_FAILED(err)) { goto done; } - err = preconfig_parse_cmdline(config, &cmdline); + err = _PyPreCmdline_Read(&cmdline); if (_Py_INIT_FAILED(err)) { goto done; } + _PyPreCmdline_SetPreConfig(&cmdline, config); + err = preconfig_read(config, &cmdline); if (_Py_INIT_FAILED(err)) { goto done; @@ -635,7 +654,7 @@ preconfig_from_argv(_PyPreConfig *config, const _PyArgv *args) err = _Py_INIT_OK(); done: - precmdline_clear(&cmdline); + _PyPreCmdline_Clear(&cmdline); return err; } -- cgit v1.2.1 From 9b4a1b1e23d4a7cb18ad26f405bdc741af69f342 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Wed, 20 Mar 2019 03:16:25 -0600 Subject: bpo-36374: Fix a possible null pointer dereference (GH-12449) https://bugs.python.org/issue36374 --- Python/compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/compile.c b/Python/compile.c index 697833752b..3656a7e00e 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1210,7 +1210,7 @@ merge_consts_recursive(struct compiler *c, PyObject *o) PyObject *t = PyDict_SetDefault(c->c_const_cache, key, key); if (t != key) { // o is registered in c_const_cache. Just use it. - Py_INCREF(t); + Py_XINCREF(t); Py_DECREF(key); return t; } -- cgit v1.2.1 From 97f5de01adf993aee17dcd26e22ae421d013f372 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 22 Mar 2019 01:30:32 -0600 Subject: bpo-35284: Fix the error handling in the compiler's compiler_call(). (GH-10625) compiler_call() needs to check if an error occurred during the maybe_optimize_method_call() call. --- Python/compile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Python') diff --git a/Python/compile.c b/Python/compile.c index 3656a7e00e..a992e4b465 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3879,6 +3879,7 @@ check_index(struct compiler *c, expr_ty e, slice_ty s) } } +// Return 1 if the method call was optimized, -1 if not, and 0 on error. static int maybe_optimize_method_call(struct compiler *c, expr_ty e) { @@ -3912,8 +3913,10 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e) static int compiler_call(struct compiler *c, expr_ty e) { - if (maybe_optimize_method_call(c, e) > 0) - return 1; + int ret = maybe_optimize_method_call(c, e); + if (ret >= 0) { + return ret; + } if (!check_caller(c, e->v.Call.func)) { return 0; } -- cgit v1.2.1 From 6d5ee973f0600a3a9444f569dcf0dd346bfa2a11 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 23 Mar 2019 12:05:43 +0100 Subject: bpo-36301: Add _PyRuntimeState.preconfig (GH-12506) _PyPreConfig_Write() now writes the applied pre-configuration into _PyRuntimeState.preconfig. --- Python/coreconfig.c | 22 ++++++++++++++++++++++ Python/preconfig.c | 9 +++++++++ Python/pystate.c | 3 +++ 3 files changed, 34 insertions(+) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 1881f00bf2..540e608fb0 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -5,6 +5,7 @@ #include "pycore_getopt.h" #include "pycore_pylifecycle.h" #include "pycore_pymem.h" +#include "pycore_pystate.h" /* _PyRuntime */ #include "pycore_pathconfig.h" #include /* setlocale() */ #ifdef HAVE_LANGINFO_H @@ -1358,6 +1359,17 @@ done: } +static _PyInitError +_PyCoreConfig_GetPreConfig(_PyCoreConfig *config) +{ + /* Read config written by _PyPreConfig_Write() */ + if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) { + return _Py_INIT_NO_MEMORY(); + } + return _Py_INIT_OK(); +} + + /* Read the configuration into _PyCoreConfig from: * Environment variables @@ -1374,6 +1386,11 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) return err; } + err = _PyCoreConfig_GetPreConfig(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + _PyCoreConfig_GetGlobalConfig(config); if (preconfig != NULL) { @@ -2117,6 +2134,11 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args, { _PyInitError err; + err = _Py_PreInitialize(); + if (_Py_INIT_FAILED(err)) { + return err; + } + _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT}; err = _PyPreCmdline_Init(&cmdline.precmdline, args); diff --git a/Python/preconfig.c b/Python/preconfig.c index d856c124f3..13e5e1e857 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -862,5 +862,14 @@ _PyPreConfig_Write(_PyPreConfig *config) /* Set LC_CTYPE to the user preferred locale */ _Py_SetLocaleFromEnv(LC_CTYPE); + /* Write the new pre-configuration into _PyRuntime */ + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + int res = _PyPreConfig_Copy(&_PyRuntime.preconfig, config); + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + if (res < 0) { + return _Py_INIT_NO_MEMORY(); + } + return _Py_INIT_OK(); } diff --git a/Python/pystate.c b/Python/pystate.c index 36566b7671..6fe3dd1ff3 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -41,6 +41,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime) _PyGC_Initialize(&runtime->gc); _PyEval_Initialize(&runtime->ceval); + runtime->preconfig = _PyPreConfig_INIT; runtime->gilstate.check_enabled = 1; @@ -97,6 +98,8 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime) runtime->xidregistry.mutex = NULL; } + _PyPreConfig_Clear(&runtime->preconfig); + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } -- cgit v1.2.1 From d3c72a223a5f771f964fc34557c55eb5bfa0f5a0 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 23 Mar 2019 21:04:40 +0900 Subject: bpo-36381: warn when no PY_SSIZE_T_CLEAN defined (GH-12473) We will remove int support from 3.10 or 4.0. --- Python/getargs.c | 15 +++++++++++++-- Python/modsupport.c | 21 ++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'Python') diff --git a/Python/getargs.c b/Python/getargs.c index e50f9b5f5c..59f0fdabb7 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -681,7 +681,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, /* For # codes */ #define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\ if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \ - else q=va_arg(*p_va, int*); + else { \ + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { \ + return NULL; \ + } \ + q=va_arg(*p_va, int*); \ + } #define STORE_SIZE(s) \ if (flags & FLAG_SIZE_T) \ *q2=s; \ @@ -2591,8 +2597,13 @@ skipitem(const char **p_format, va_list *p_va, int flags) if (p_va != NULL) { if (flags & FLAG_SIZE_T) (void) va_arg(*p_va, Py_ssize_t *); - else + else { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { + return NULL; + } (void) va_arg(*p_va, int *); + } } format++; } else if ((c == 's' || c == 'z' || c == 'y' || c == 'w') diff --git a/Python/modsupport.c b/Python/modsupport.c index 8a77a7b06d..6255822107 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -342,8 +342,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) ++*p_format; if (flags & FLAG_SIZE_T) n = va_arg(*p_va, Py_ssize_t); - else + else { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { + return NULL; + } n = va_arg(*p_va, int); + } } else n = -1; @@ -390,8 +395,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) ++*p_format; if (flags & FLAG_SIZE_T) n = va_arg(*p_va, Py_ssize_t); - else + else { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { + return NULL; + } n = va_arg(*p_va, int); + } } else n = -1; @@ -423,8 +433,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) ++*p_format; if (flags & FLAG_SIZE_T) n = va_arg(*p_va, Py_ssize_t); - else + else { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { + return NULL; + } n = va_arg(*p_va, int); + } } else n = -1; -- cgit v1.2.1 From f72346c47537657a287a862305f65eb5d7594fbf Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 25 Mar 2019 17:54:58 +0100 Subject: bpo-36301: Cleanup preconfig code (GH-12535) Prepare code to move some _PyPreConfig parameters into _PyPreCmdline. Changes: * _PyCoreConfig_ReadFromArgv(): remove preconfig parameter, use _PyRuntime.preconfig. * Add _PyPreCmdline_GetPreConfig() (called by _PyPreConfig_Read()). * Rename _PyPreCmdline_Init() to _PyPreCmdline_SetArgv() * Factorize _Py_PreInitializeFromPreConfig() code: add pyinit_preinit(). * _PyPreConfig_Read() now sets coerce_c_locale to 2 if it must be coerced. * Remove _PyCoreConfig_ReadPreConfig(). * _PyCoreConfig_Write() now copies updated preconfig into _PyRuntime. --- Python/coreconfig.c | 86 +++++++++------------------------- Python/pathconfig.c | 2 +- Python/preconfig.c | 127 ++++++++++++++++++++++++++------------------------- Python/pylifecycle.c | 61 ++++++++++++------------- 4 files changed, 116 insertions(+), 160 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 540e608fb0..130dfccc4d 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1330,46 +1330,6 @@ config_init_fs_encoding(_PyCoreConfig *config) } -static _PyInitError -_PyCoreConfig_ReadPreConfig(_PyCoreConfig *config) -{ - _PyInitError err; - _PyPreConfig local_preconfig = _PyPreConfig_INIT; - _PyPreConfig_GetGlobalConfig(&local_preconfig); - - if (_PyPreConfig_Copy(&local_preconfig, &config->preconfig) < 0) { - err = _Py_INIT_NO_MEMORY(); - goto done; - } - - err = _PyPreConfig_Read(&local_preconfig); - if (_Py_INIT_FAILED(err)) { - goto done; - } - - if (_PyPreConfig_Copy(&config->preconfig, &local_preconfig) < 0) { - err = _Py_INIT_NO_MEMORY(); - goto done; - } - err = _Py_INIT_OK(); - -done: - _PyPreConfig_Clear(&local_preconfig); - return err; -} - - -static _PyInitError -_PyCoreConfig_GetPreConfig(_PyCoreConfig *config) -{ - /* Read config written by _PyPreConfig_Write() */ - if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) { - return _Py_INIT_NO_MEMORY(); - } - return _Py_INIT_OK(); -} - - /* Read the configuration into _PyCoreConfig from: * Environment variables @@ -1377,7 +1337,7 @@ _PyCoreConfig_GetPreConfig(_PyCoreConfig *config) See _PyCoreConfig_ReadFromArgv() to parse also command line arguments. */ _PyInitError -_PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) +_PyCoreConfig_Read(_PyCoreConfig *config) { _PyInitError err; @@ -1386,25 +1346,12 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) return err; } - err = _PyCoreConfig_GetPreConfig(config); - if (_Py_INIT_FAILED(err)) { - return err; + if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) { + return _Py_INIT_NO_MEMORY(); } _PyCoreConfig_GetGlobalConfig(config); - if (preconfig != NULL) { - if (_PyPreConfig_Copy(&config->preconfig, preconfig) < 0) { - return _Py_INIT_NO_MEMORY(); - } - } - else { - err = _PyCoreConfig_ReadPreConfig(config); - if (_Py_INIT_FAILED(err)) { - return err; - } - } - assert(config->preconfig.use_environment >= 0); if (config->preconfig.isolated > 0) { @@ -1548,11 +1495,22 @@ config_init_stdio(const _PyCoreConfig *config) - set Py_xxx global configuration variables - initialize C standard streams (stdin, stdout, stderr) */ -void +_PyInitError _PyCoreConfig_Write(const _PyCoreConfig *config) { _PyCoreConfig_SetGlobalConfig(config); config_init_stdio(config); + + /* Write the new pre-configuration into _PyRuntime */ + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + int res = _PyPreConfig_Copy(&_PyRuntime.preconfig, &config->preconfig); + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + if (res < 0) { + return _Py_INIT_NO_MEMORY(); + } + + return _Py_INIT_OK(); } @@ -2047,8 +2005,7 @@ config_usage(int error, const wchar_t* program) /* Parse command line options and environment variables. */ static _PyInitError -config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, - const _PyPreConfig *preconfig) +config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) { int need_usage = 0; _PyInitError err; @@ -2067,7 +2024,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, return err; } - _PyPreCmdline_SetPreConfig(&cmdline->precmdline, &config->preconfig); + _PyPreCmdline_SetPreConfig(&cmdline->precmdline, &_PyRuntime.preconfig); if (_PyWstrList_Extend(&config->xoptions, &cmdline->precmdline.xoptions) < 0) { return _Py_INIT_NO_MEMORY(); } @@ -2098,7 +2055,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, return err; } - err = _PyCoreConfig_Read(config, preconfig); + err = _PyCoreConfig_Read(config); if (_Py_INIT_FAILED(err)) { return err; } @@ -2129,8 +2086,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, * Environment variables * Py_xxx global configuration variables */ _PyInitError -_PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args, - const _PyPreConfig *preconfig) +_PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args) { _PyInitError err; @@ -2141,12 +2097,12 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args, _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT}; - err = _PyPreCmdline_Init(&cmdline.precmdline, args); + err = _PyPreCmdline_SetArgv(&cmdline.precmdline, args); if (_Py_INIT_FAILED(err)) { goto done; } - err = config_from_cmdline(config, &cmdline, preconfig); + err = config_from_cmdline(config, &cmdline); if (_Py_INIT_FAILED(err)) { goto done; } diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 0ccb898e42..f0b13fd1b0 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -394,7 +394,7 @@ pathconfig_global_init(void) _PyInitError err; _PyCoreConfig config = _PyCoreConfig_INIT; - err = _PyCoreConfig_Read(&config, NULL); + err = _PyCoreConfig_Read(&config); if (_Py_INIT_FAILED(err)) { goto error; } diff --git a/Python/preconfig.c b/Python/preconfig.c index 13e5e1e857..c16f34083e 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -111,12 +111,27 @@ _PyPreCmdline_Clear(_PyPreCmdline *cmdline) _PyInitError -_PyPreCmdline_Init(_PyPreCmdline *cmdline, const _PyArgv *args) +_PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) { return _PyArgv_AsWstrList(args, &cmdline->argv); } +static void +_PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (config->ATTR != -1) { \ + cmdline->ATTR = config->ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + +#undef COPY_ATTR +} + + /* --- _PyPreConfig ----------------------------------------------- */ void @@ -336,24 +351,28 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) static void preconfig_init_locale(_PyPreConfig *config) { - /* Test also if coerce_c_locale equals 1: PYTHONCOERCECLOCALE=1 doesn't - imply that the C locale is always coerced. It is only coerced if - if the LC_CTYPE locale is "C". */ - if (config->coerce_c_locale != 0) { - /* The C locale enables the C locale coercion (PEP 538) */ - if (_Py_LegacyLocaleDetected()) { - config->coerce_c_locale = 1; - } - else { - config->coerce_c_locale = 0; - } + /* The C locale enables the C locale coercion (PEP 538) */ + if (_Py_LegacyLocaleDetected()) { + config->coerce_c_locale = 2; + } + else { + config->coerce_c_locale = 0; } } static _PyInitError -preconfig_read(_PyPreConfig *config, const _PyPreCmdline *cmdline) +preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) { + _PyInitError err; + + err = _PyPreCmdline_Read(cmdline); + if (_Py_INIT_FAILED(err)) { + return err; + } + + _PyPreCmdline_SetPreConfig(cmdline, config); + _PyPreConfig_GetGlobalConfig(config); /* isolated and use_environment */ @@ -398,13 +417,16 @@ preconfig_read(_PyPreConfig *config, const _PyPreCmdline *cmdline) #endif if (config->utf8_mode < 0) { - _PyInitError err = preconfig_init_utf8_mode(config, cmdline); + err = preconfig_init_utf8_mode(config, cmdline); if (_Py_INIT_FAILED(err)) { return err; } } - if (config->coerce_c_locale != 0) { + /* Test also if coerce_c_locale equals 1: PYTHONCOERCECLOCALE=1 doesn't + imply that the C locale is always coerced. It is only coerced if + if the LC_CTYPE locale is "C". */ + if (config->coerce_c_locale != 0 && config->coerce_c_locale != 2) { preconfig_init_locale(config); } @@ -491,36 +513,6 @@ get_ctype_locale(char **locale_p) } -/* Read the configuration from: - - - environment variables - - Py_xxx global configuration variables - - the LC_CTYPE locale - - See _PyPreConfig_ReadFromArgv() to parse also command line arguments. */ -_PyInitError -_PyPreConfig_Read(_PyPreConfig *config) -{ - _PyInitError err; - char *old_loc; - - err = get_ctype_locale(&old_loc); - if (_Py_INIT_FAILED(err)) { - return err; - } - - /* Set LC_CTYPE to the user preferred locale */ - _Py_SetLocaleFromEnv(LC_CTYPE); - - err = preconfig_read(config, NULL); - - setlocale(LC_CTYPE, old_loc); - PyMem_RawFree(old_loc); - - return err; -} - - void _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) { @@ -628,33 +620,46 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline) } -static _PyInitError -preconfig_from_argv(_PyPreConfig *config, const _PyArgv *args) +/* Read the configuration from: + + - environment variables + - Py_xxx global configuration variables + - the LC_CTYPE locale + + See _PyPreConfig_ReadFromArgv() to parse also command line arguments. */ +_PyInitError +_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) { _PyInitError err; - _PyPreCmdline cmdline = _PyPreCmdline_INIT; + char *old_loc = NULL; - err = _PyPreCmdline_Init(&cmdline, args); + err = get_ctype_locale(&old_loc); if (_Py_INIT_FAILED(err)) { goto done; } - err = _PyPreCmdline_Read(&cmdline); - if (_Py_INIT_FAILED(err)) { - goto done; - } + /* Set LC_CTYPE to the user preferred locale */ + _Py_SetLocaleFromEnv(LC_CTYPE); - _PyPreCmdline_SetPreConfig(&cmdline, config); + _PyPreCmdline_GetPreConfig(&cmdline, config); - err = preconfig_read(config, &cmdline); - if (_Py_INIT_FAILED(err)) { - goto done; + if (args) { + err = _PyPreCmdline_SetArgv(&cmdline, args); + if (_Py_INIT_FAILED(err)) { + goto done; + } } - err = _Py_INIT_OK(); + + err = preconfig_read(config, &cmdline); done: + if (old_loc != NULL) { + setlocale(LC_CTYPE, old_loc); + PyMem_RawFree(old_loc); + } _PyPreCmdline_Clear(&cmdline); + return err; } @@ -719,15 +724,11 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif - err = preconfig_from_argv(config, args); + err = _PyPreConfig_Read(config, args); if (_Py_INIT_FAILED(err)) { goto done; } - if (locale_coerced) { - config->coerce_c_locale = 1; - } - /* The legacy C locale assumes ASCII as the default text encoding, which * causes problems not only for the CPython runtime, but also other * components like GNU readline. diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 994a94f140..ea1b731a56 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -714,23 +714,8 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, } -_PyInitError -_Py_PreInitializeFromPreConfig(_PyPreConfig *config) -{ - if (config != NULL) { - _PyInitError err = _PyPreConfig_Write(config); - if (_Py_INIT_FAILED(err)) { - return err; - } - } - - _PyRuntime.pre_initialized = 1; - return _Py_INIT_OK(); -} - - static _PyInitError -pyinit_preconfig(_PyPreConfig *config, const _PyPreConfig *src_config) +pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) { _PyInitError err; @@ -739,32 +724,46 @@ pyinit_preconfig(_PyPreConfig *config, const _PyPreConfig *src_config) return err; } - if (_PyPreConfig_Copy(config, src_config) < 0) { - return _Py_INIT_ERR("failed to copy pre config"); + if (_PyRuntime.pre_initialized) { + /* If it's already configured: ignored the new configuration */ + return _Py_INIT_OK(); + } + + if (src_config) { + if (_PyPreConfig_Copy(config, src_config) < 0) { + return _Py_INIT_ERR("failed to copy pre config"); + } + } + + err = _PyPreConfig_Read(config, NULL); + if (_Py_INIT_FAILED(err)) { + return err; } - err = _PyPreConfig_Read(config); + err = _PyPreConfig_Write(config); if (_Py_INIT_FAILED(err)) { return err; } - return _Py_PreInitializeFromPreConfig(config); + _PyRuntime.pre_initialized = 1; + return _Py_INIT_OK(); } _PyInitError -_Py_PreInitialize(void) +_Py_PreInitializeFromPreConfig(_PyPreConfig *config) { - _PyInitError err = _PyRuntime_Initialize(); - if (_Py_INIT_FAILED(err)) { - return err; - } + return pyinit_preinit(config, NULL); +} - if (_PyRuntime.pre_initialized) { - return _Py_INIT_OK(); - } - return _Py_PreInitializeFromPreConfig(NULL); +_PyInitError +_Py_PreInitialize(void) +{ + _PyPreConfig config = _PyPreConfig_INIT; + _PyInitError err = pyinit_preinit(&config, NULL); + _PyPreConfig_Clear(&config); + return err; } @@ -776,7 +775,7 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, return _Py_INIT_ERR("failed to copy core config"); } - _PyInitError err = _PyCoreConfig_Read(config, NULL); + _PyInitError err = _PyCoreConfig_Read(config); if (_Py_INIT_FAILED(err)) { return err; } @@ -817,7 +816,7 @@ _Py_InitializeCore(PyInterpreterState **interp_p, _PyCoreConfig local_config = _PyCoreConfig_INIT; - err = pyinit_preconfig(&local_config.preconfig, &src_config->preconfig); + err = pyinit_preinit(&local_config.preconfig, &src_config->preconfig); if (_Py_INIT_FAILED(err)) { goto done; } -- cgit v1.2.1 From a6fbc4e25e1dc7d1c9a26888b9115bc6c2afc101 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 25 Mar 2019 18:37:10 +0100 Subject: bpo-36301: Add _Py_PreInitializeFromConfig() (GH-12536) * Initialize _PyPreConfig.dev_mode to -1. * _PyPreConfig_Read(): coreconfig has the priority over preconfig. * _PyCoreConfig_Read() now calls _PyPreCmdline_Read() internally. * config_from_cmdline() now pass _PyPreCmdline to config_read(). * Add _PyPreCmdline_Copy(). --- Python/coreconfig.c | 62 +++++++++++++++++++++++++++++++++++++++++++++------- Python/preconfig.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--- Python/pylifecycle.c | 35 +++++++++++++++++++---------- 3 files changed, 137 insertions(+), 22 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 130dfccc4d..ba5abb6ca4 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1336,16 +1336,30 @@ config_init_fs_encoding(_PyCoreConfig *config) * Py_xxx global configuration variables See _PyCoreConfig_ReadFromArgv() to parse also command line arguments. */ -_PyInitError -_PyCoreConfig_Read(_PyCoreConfig *config) +static _PyInitError +config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; - err = _Py_PreInitialize(); + err = _Py_PreInitializeFromConfig(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + + _PyPreCmdline_GetPreConfig(cmdline, &_PyRuntime.preconfig); + _PyPreCmdline_GetCoreConfig(cmdline, config); + + err = _PyPreCmdline_Read(cmdline); if (_Py_INIT_FAILED(err)) { return err; } + _PyPreCmdline_SetCoreConfig(cmdline, config); + + if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) { + return _Py_INIT_NO_MEMORY(); + } + if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) { return _Py_INIT_NO_MEMORY(); } @@ -1454,6 +1468,41 @@ _PyCoreConfig_Read(_PyCoreConfig *config) } +static _PyInitError +config_read(_PyCoreConfig *config, const _PyPreCmdline *src_cmdline) +{ + _PyInitError err; + + err = _Py_PreInitializeFromConfig(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + + _PyPreCmdline cmdline = _PyPreCmdline_INIT; + + if (src_cmdline) { + if (_PyPreCmdline_Copy(&cmdline, src_cmdline) < 0) { + err = _Py_INIT_NO_MEMORY(); + goto done; + } + } + + err = config_read_impl(config, &cmdline); + +done: + _PyPreCmdline_Clear(&cmdline); + return err; + +} + + +_PyInitError +_PyCoreConfig_Read(_PyCoreConfig *config) +{ + return config_read(config, NULL); +} + + static void config_init_stdio(const _PyCoreConfig *config) { @@ -2025,9 +2074,6 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) } _PyPreCmdline_SetPreConfig(&cmdline->precmdline, &_PyRuntime.preconfig); - if (_PyWstrList_Extend(&config->xoptions, &cmdline->precmdline.xoptions) < 0) { - return _Py_INIT_NO_MEMORY(); - } err = config_parse_cmdline(config, cmdline, &need_usage); if (_Py_INIT_FAILED(err)) { @@ -2055,7 +2101,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) return err; } - err = _PyCoreConfig_Read(config); + err = config_read(config, &cmdline->precmdline); if (_Py_INIT_FAILED(err)) { return err; } @@ -2090,7 +2136,7 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args) { _PyInitError err; - err = _Py_PreInitialize(); + err = _Py_PreInitializeFromConfig(config); if (_Py_INIT_FAILED(err)) { return err; } diff --git a/Python/preconfig.c b/Python/preconfig.c index c16f34083e..ac87a7a3c7 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -110,6 +110,22 @@ _PyPreCmdline_Clear(_PyPreCmdline *cmdline) } +int +_PyPreCmdline_Copy(_PyPreCmdline *cmdline, const _PyPreCmdline *cmdline2) +{ + _PyPreCmdline_Clear(cmdline); + if (_PyWstrList_Copy(&cmdline->argv, &cmdline2->argv) < 0) { + return -1; + } + if (_PyWstrList_Copy(&cmdline->xoptions, &cmdline2->xoptions) < 0) { + return -1; + } + cmdline->use_environment = cmdline2->use_environment; + cmdline->isolated = cmdline2->isolated; + return 0; +} + + _PyInitError _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) { @@ -117,7 +133,7 @@ _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) } -static void +void _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) { #define COPY_ATTR(ATTR) \ @@ -132,6 +148,36 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) } +void +_PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (config->preconfig.ATTR != -1) { \ + cmdline->ATTR = config->preconfig.ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + +#undef COPY_ATTR +} + + +void +_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (config->preconfig.ATTR == -1 && cmdline->ATTR != -1) { \ + config->preconfig.ATTR = cmdline->ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + +#undef COPY_ATTR +} + + /* --- _PyPreConfig ----------------------------------------------- */ void @@ -628,7 +674,8 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline) See _PyPreConfig_ReadFromArgv() to parse also command line arguments. */ _PyInitError -_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) +_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, + const _PyCoreConfig *coreconfig) { _PyInitError err; _PyPreCmdline cmdline = _PyPreCmdline_INIT; @@ -642,8 +689,17 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) /* Set LC_CTYPE to the user preferred locale */ _Py_SetLocaleFromEnv(LC_CTYPE); + _PyPreConfig_GetGlobalConfig(config); + _PyPreCmdline_GetPreConfig(&cmdline, config); + if (coreconfig) { + _PyPreCmdline_GetCoreConfig(&cmdline, coreconfig); + if (config->dev_mode == -1) { + config->dev_mode = coreconfig->preconfig.dev_mode; + } + } + if (args) { err = _PyPreCmdline_SetArgv(&cmdline, args); if (_Py_INIT_FAILED(err)) { @@ -724,7 +780,7 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif - err = _PyPreConfig_Read(config, args); + err = _PyPreConfig_Read(config, args, NULL); if (_Py_INIT_FAILED(err)) { goto done; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ea1b731a56..66cadc99c7 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -715,7 +715,9 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, static _PyInitError -pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) +pyinit_preinit(_PyPreConfig *config, + const _PyPreConfig *src_config, + const _PyCoreConfig *coreconfig) { _PyInitError err; @@ -729,13 +731,17 @@ pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) return _Py_INIT_OK(); } + if (!src_config && coreconfig) { + src_config = &coreconfig->preconfig; + } + if (src_config) { if (_PyPreConfig_Copy(config, src_config) < 0) { return _Py_INIT_ERR("failed to copy pre config"); } } - err = _PyPreConfig_Read(config, NULL); + err = _PyPreConfig_Read(config, NULL, coreconfig); if (_Py_INIT_FAILED(err)) { return err; } @@ -750,18 +756,28 @@ pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) } +_PyInitError +_Py_PreInitialize(void) +{ + _PyPreConfig config = _PyPreConfig_INIT; + _PyInitError err = pyinit_preinit(&config, NULL, NULL); + _PyPreConfig_Clear(&config); + return err; +} + + _PyInitError _Py_PreInitializeFromPreConfig(_PyPreConfig *config) { - return pyinit_preinit(config, NULL); + return pyinit_preinit(config, NULL, NULL); } _PyInitError -_Py_PreInitialize(void) +_Py_PreInitializeFromConfig(const _PyCoreConfig *coreconfig) { _PyPreConfig config = _PyPreConfig_INIT; - _PyInitError err = pyinit_preinit(&config, NULL); + _PyInitError err = pyinit_preinit(&config, NULL, coreconfig); _PyPreConfig_Clear(&config); return err; } @@ -814,16 +830,13 @@ _Py_InitializeCore(PyInterpreterState **interp_p, assert(src_config != NULL); - _PyCoreConfig local_config = _PyCoreConfig_INIT; - - err = pyinit_preinit(&local_config.preconfig, &src_config->preconfig); + err = _Py_PreInitializeFromConfig(src_config); if (_Py_INIT_FAILED(err)) { - goto done; + return err; } + _PyCoreConfig local_config = _PyCoreConfig_INIT; err = pyinit_coreconfig(&local_config, src_config, interp_p); - -done: _PyCoreConfig_Clear(&local_config); return err; } -- cgit v1.2.1 From 027b09c5a13aac9e14a3b43bb385298d549c3833 Mon Sep 17 00:00:00 2001 From: Stefan Krah Date: Mon, 25 Mar 2019 21:50:58 +0100 Subject: bpo-36370: Check for PyErr_Occurred() after PyImport_GetModule() (GH-12504) --- Python/ceval.c | 6 +++--- Python/import.c | 19 ++++++++++++++----- Python/pylifecycle.c | 6 ++++-- Python/sysmodule.c | 4 +++- 4 files changed, 24 insertions(+), 11 deletions(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index 40320bf357..28e923219d 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4948,7 +4948,7 @@ import_from(PyObject *v, PyObject *name) } x = PyImport_GetModule(fullmodname); Py_DECREF(fullmodname); - if (x == NULL) { + if (x == NULL && !PyErr_Occurred()) { goto error; } Py_DECREF(pkgname); @@ -4971,7 +4971,7 @@ import_from(PyObject *v, PyObject *name) "cannot import name %R from %R (unknown location)", name, pkgname_or_unknown ); - /* NULL check for errmsg done by PyErr_SetImportError. */ + /* NULL checks for errmsg and pkgname done by PyErr_SetImportError. */ PyErr_SetImportError(errmsg, pkgname, NULL); } else { @@ -4979,7 +4979,7 @@ import_from(PyObject *v, PyObject *name) "cannot import name %R from %R (%S)", name, pkgname_or_unknown, pkgpath ); - /* NULL check for errmsg done by PyErr_SetImportError. */ + /* NULL checks for errmsg and pkgname done by PyErr_SetImportError. */ PyErr_SetImportError(errmsg, pkgname, pkgpath); } diff --git a/Python/import.c b/Python/import.c index bf3a99414f..c00c3aa640 100644 --- a/Python/import.c +++ b/Python/import.c @@ -966,11 +966,10 @@ exec_code_in_module(PyObject *name, PyObject *module_dict, PyObject *code_object Py_DECREF(v); m = PyImport_GetModule(name); - if (m == NULL) { + if (m == NULL && !PyErr_Occurred()) { PyErr_Format(PyExc_ImportError, "Loaded module %R not found in sys.modules", name); - return NULL; } return m; @@ -1735,6 +1734,10 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } mod = PyImport_GetModule(abs_name); + if (mod == NULL && PyErr_Occurred()) { + goto error; + } + if (mod != NULL && mod != Py_None) { _Py_IDENTIFIER(__spec__); _Py_IDENTIFIER(_lock_unlock_module); @@ -1810,9 +1813,11 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, final_mod = PyImport_GetModule(to_return); Py_DECREF(to_return); if (final_mod == NULL) { - PyErr_Format(PyExc_KeyError, - "%R not in sys.modules as expected", - to_return); + if (!PyErr_Occurred()) { + PyErr_Format(PyExc_KeyError, + "%R not in sys.modules as expected", + to_return); + } goto error; } } @@ -1875,6 +1880,10 @@ PyImport_ReloadModule(PyObject *m) PyObject *reloaded_module = NULL; PyObject *imp = _PyImport_GetModuleId(&PyId_imp); if (imp == NULL) { + if (PyErr_Occurred()) { + return NULL; + } + imp = PyImport_ImportModule("imp"); if (imp == NULL) { return NULL; diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 66cadc99c7..e08f290d8d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2157,8 +2157,10 @@ wait_for_thread_shutdown(void) PyObject *result; PyObject *threading = _PyImport_GetModuleId(&PyId_threading); if (threading == NULL) { - /* threading not imported */ - PyErr_Clear(); + if (PyErr_Occurred()) { + PyErr_WriteUnraisable(NULL); + } + /* else: threading not imported */ return; } result = _PyObject_CallMethodId(threading, &PyId__shutdown, NULL); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4351a7fb37..3df4d44a7c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -283,7 +283,9 @@ sys_displayhook(PyObject *module, PyObject *o) builtins = _PyImport_GetModuleId(&PyId_builtins); if (builtins == NULL) { - PyErr_SetString(PyExc_RuntimeError, "lost builtins module"); + if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_RuntimeError, "lost builtins module"); + } return NULL; } Py_DECREF(builtins); -- cgit v1.2.1 From 1075d1684ab84dc7c28d93cfb46e95e70d3b6d3b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 25 Mar 2019 23:19:57 +0100 Subject: bpo-36301: Add _Py_GetConfigsAsDict() function (GH-12540) * Add _Py_GetConfigsAsDict() function to get all configurations as a dict. * dump_config() of _testembed.c now dumps preconfig as a separated key: call _Py_GetConfigsAsDict(). * Make _PyMainInterpreterConfig_AsDict() private. --- Python/coreconfig.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++----- Python/preconfig.c | 16 +++++++++--- 2 files changed, 78 insertions(+), 11 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index ba5abb6ca4..a434b258f2 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -131,7 +131,7 @@ int Py_LegacyWindowsStdioFlag = 0; /* Uses FileIO instead of WindowsConsoleIO */ #endif -PyObject * +static PyObject * _Py_GetGlobalVariablesAsDict(void) { PyObject *dict, *obj; @@ -1563,7 +1563,7 @@ _PyCoreConfig_Write(const _PyCoreConfig *config) } -PyObject * +static PyObject * _PyCoreConfig_AsDict(const _PyCoreConfig *config) { PyObject *dict; @@ -1573,11 +1573,6 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config) return NULL; } - if (_PyPreConfig_AsDict(&config->preconfig, dict) < 0) { - Py_DECREF(dict); - return NULL; - } - #define SET_ITEM(KEY, EXPR) \ do { \ PyObject *obj = (EXPR); \ @@ -2158,3 +2153,67 @@ done: cmdline_clear(&cmdline); return err; } + + +PyObject* +_Py_GetConfigsAsDict(void) +{ + PyObject *config = NULL; + PyObject *dict = NULL; + + config = PyDict_New(); + if (config == NULL) { + goto error; + } + + /* global config */ + dict = _Py_GetGlobalVariablesAsDict(); + if (dict == NULL) { + goto error; + } + if (PyDict_SetItemString(config, "global_config", dict) < 0) { + goto error; + } + Py_CLEAR(dict); + + /* pre config */ + PyInterpreterState *interp = _PyInterpreterState_Get(); + const _PyCoreConfig *core_config = _PyInterpreterState_GetCoreConfig(interp); + const _PyPreConfig *pre_config = &core_config->preconfig; + dict = _PyPreConfig_AsDict(pre_config); + if (dict == NULL) { + goto error; + } + if (PyDict_SetItemString(config, "pre_config", dict) < 0) { + goto error; + } + Py_CLEAR(dict); + + /* core config */ + dict = _PyCoreConfig_AsDict(core_config); + if (dict == NULL) { + goto error; + } + if (PyDict_SetItemString(config, "core_config", dict) < 0) { + goto error; + } + Py_CLEAR(dict); + + /* main config */ + const _PyMainInterpreterConfig *main_config = _PyInterpreterState_GetMainConfig(interp); + dict = _PyMainInterpreterConfig_AsDict(main_config); + if (dict == NULL) { + goto error; + } + if (PyDict_SetItemString(config, "main_config", dict) < 0) { + goto error; + } + Py_CLEAR(dict); + + return config; + +error: + Py_XDECREF(config); + Py_XDECREF(dict); + return NULL; +} diff --git a/Python/preconfig.c b/Python/preconfig.c index ac87a7a3c7..c65ee28f73 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -574,9 +574,16 @@ _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) } -int -_PyPreConfig_AsDict(const _PyPreConfig *config, PyObject *dict) +PyObject* +_PyPreConfig_AsDict(const _PyPreConfig *config) { + PyObject *dict; + + dict = PyDict_New(); + if (dict == NULL) { + return NULL; + } + #define SET_ITEM(KEY, EXPR) \ do { \ PyObject *obj = (EXPR); \ @@ -608,10 +615,11 @@ _PyPreConfig_AsDict(const _PyPreConfig *config, PyObject *dict) #endif SET_ITEM_INT(dev_mode); SET_ITEM_STR(allocator); - return 0; + return dict; fail: - return -1; + Py_DECREF(dict); + return NULL; #undef FROM_STRING #undef SET_ITEM -- cgit v1.2.1 From f78a5e9ce8f32a195f5f788aade79578437f30a6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Mar 2019 00:03:15 +0100 Subject: bpo-36301: Add _Py_GetEnv() function (GH-12542) * Make _PyPreConfig_GetEnv(), _PyCoreConfig_GetEnv() and _PyCoreConfig_GetEnvDup() private * _Py_get_env_flag() first parameter becomes "int use_environment" --- Python/coreconfig.c | 24 ++++++++++++------------ Python/preconfig.c | 22 +++++++++++++++------- 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index a434b258f2..1245aef54b 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -610,14 +610,14 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) } -const char* +static const char* _PyCoreConfig_GetEnv(const _PyCoreConfig *config, const char *name) { - return _PyPreConfig_GetEnv(&config->preconfig, name); + return _Py_GetEnv(config->preconfig.use_environment, name); } -int +static int _PyCoreConfig_GetEnvDup(const _PyCoreConfig *config, wchar_t **dest, wchar_t *wname, char *name) @@ -924,34 +924,34 @@ config_wstr_to_int(const wchar_t *wstr, int *result) static _PyInitError config_read_env_vars(_PyCoreConfig *config) { - _PyPreConfig *preconfig = &config->preconfig; + int use_env = config->preconfig.use_environment; /* Get environment variables */ - _Py_get_env_flag(preconfig, &config->parser_debug, "PYTHONDEBUG"); - _Py_get_env_flag(preconfig, &config->verbose, "PYTHONVERBOSE"); - _Py_get_env_flag(preconfig, &config->optimization_level, "PYTHONOPTIMIZE"); - _Py_get_env_flag(preconfig, &config->inspect, "PYTHONINSPECT"); + _Py_get_env_flag(use_env, &config->parser_debug, "PYTHONDEBUG"); + _Py_get_env_flag(use_env, &config->verbose, "PYTHONVERBOSE"); + _Py_get_env_flag(use_env, &config->optimization_level, "PYTHONOPTIMIZE"); + _Py_get_env_flag(use_env, &config->inspect, "PYTHONINSPECT"); int dont_write_bytecode = 0; - _Py_get_env_flag(preconfig, &dont_write_bytecode, "PYTHONDONTWRITEBYTECODE"); + _Py_get_env_flag(use_env, &dont_write_bytecode, "PYTHONDONTWRITEBYTECODE"); if (dont_write_bytecode) { config->write_bytecode = 0; } int no_user_site_directory = 0; - _Py_get_env_flag(preconfig, &no_user_site_directory, "PYTHONNOUSERSITE"); + _Py_get_env_flag(use_env, &no_user_site_directory, "PYTHONNOUSERSITE"); if (no_user_site_directory) { config->user_site_directory = 0; } int unbuffered_stdio = 0; - _Py_get_env_flag(preconfig, &unbuffered_stdio, "PYTHONUNBUFFERED"); + _Py_get_env_flag(use_env, &unbuffered_stdio, "PYTHONUNBUFFERED"); if (unbuffered_stdio) { config->buffered_stdio = 0; } #ifdef MS_WINDOWS - _Py_get_env_flag(preconfig, &config->legacy_windows_stdio, + _Py_get_env_flag(use_env, &config->legacy_windows_stdio, "PYTHONLEGACYWINDOWSSTDIO"); #endif diff --git a/Python/preconfig.c b/Python/preconfig.c index c65ee28f73..8b685ce42d 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -270,11 +270,11 @@ _PyPreConfig_SetGlobalConfig(const _PyPreConfig *config) const char* -_PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name) +_Py_GetEnv(int use_environment, const char *name) { - assert(config->use_environment >= 0); + assert(use_environment >= 0); - if (!config->use_environment) { + if (!use_environment) { return NULL; } @@ -288,6 +288,13 @@ _PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name) } +static const char* +_PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name) +{ + return _Py_GetEnv(config->use_environment, name); +} + + int _Py_str_to_int(const char *str, int *result) { @@ -307,9 +314,9 @@ _Py_str_to_int(const char *str, int *result) void -_Py_get_env_flag(_PyPreConfig *config, int *flag, const char *name) +_Py_get_env_flag(int use_environment, int *flag, const char *name) { - const char *var = _PyPreConfig_GetEnv(config, name); + const char *var = _Py_GetEnv(use_environment, name); if (!var) { return; } @@ -434,8 +441,9 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) /* legacy_windows_fs_encoding, utf8_mode, coerce_c_locale */ if (config->use_environment) { #ifdef MS_WINDOWS - _Py_get_env_flag(config, &config->legacy_windows_fs_encoding, - "PYTHONLEGACYWINDOWSFSENCODING"); + _Py_get_env_flag(config->use_environment, + &config->legacy_windows_fs_encoding, + "PYTHONLEGACYWINDOWSFSENCODING"); #endif const char *env = _PyPreConfig_GetEnv(config, "PYTHONCOERCECLOCALE"); -- cgit v1.2.1 From 20004959d23d07ac784eef51ecb161012180faa8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Mar 2019 02:31:11 +0100 Subject: bpo-36301: Remove _PyCoreConfig.preconfig (GH-12546) * Replace _PyCoreConfig.preconfig with 3 new fields in _PyCoreConfig: isolated, use_environment, dev_mode. * Add _PyPreCmdline.dev_mode. * Add _Py_PreInitializeFromPreConfigInPlace(). --- Python/coreconfig.c | 85 ++++++++++++++++++++++------------------------------ Python/pathconfig.c | 2 +- Python/preconfig.c | 46 +++++++++++++++------------- Python/pylifecycle.c | 54 +++++++++++++++++++-------------- Python/sysmodule.c | 9 +++--- 5 files changed, 98 insertions(+), 98 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 1245aef54b..2e6eb40298 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -469,8 +469,6 @@ Py_GetArgcArgv(int *argc, wchar_t ***argv) void _PyCoreConfig_Clear(_PyCoreConfig *config) { - _PyPreConfig_Clear(&config->preconfig); - #define CLEAR(ATTR) \ do { \ PyMem_RawFree(ATTR); \ @@ -514,10 +512,6 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) { _PyCoreConfig_Clear(config); - if (_PyPreConfig_Copy(&config->preconfig, &config2->preconfig) < 0) { - return -1; - } - #define COPY_ATTR(ATTR) config->ATTR = config2->ATTR #define COPY_STR_ATTR(ATTR) \ do { \ @@ -544,6 +538,9 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) } \ } while (0) + COPY_ATTR(isolated); + COPY_ATTR(use_environment); + COPY_ATTR(dev_mode); COPY_ATTR(install_signal_handlers); COPY_ATTR(use_hash_seed); COPY_ATTR(hash_seed); @@ -613,7 +610,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) static const char* _PyCoreConfig_GetEnv(const _PyCoreConfig *config, const char *name) { - return _Py_GetEnv(config->preconfig.use_environment, name); + return _Py_GetEnv(config->use_environment, name); } @@ -622,9 +619,9 @@ _PyCoreConfig_GetEnvDup(const _PyCoreConfig *config, wchar_t **dest, wchar_t *wname, char *name) { - assert(config->preconfig.use_environment >= 0); + assert(config->use_environment >= 0); - if (!config->preconfig.use_environment) { + if (!config->use_environment) { *dest = NULL; return 0; } @@ -668,8 +665,6 @@ _PyCoreConfig_GetEnvDup(const _PyCoreConfig *config, void _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config) { - _PyPreConfig_GetGlobalConfig(&config->preconfig); - #define COPY_FLAG(ATTR, VALUE) \ if (config->ATTR == -1) { \ config->ATTR = VALUE; \ @@ -679,6 +674,8 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config) config->ATTR = !(VALUE); \ } + COPY_FLAG(isolated, Py_IsolatedFlag); + COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); COPY_FLAG(bytes_warning, Py_BytesWarningFlag); COPY_FLAG(inspect, Py_InspectFlag); COPY_FLAG(interactive, Py_InteractiveFlag); @@ -714,6 +711,8 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config) VAR = !config->ATTR; \ } + COPY_FLAG(isolated, Py_IsolatedFlag); + COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); COPY_FLAG(bytes_warning, Py_BytesWarningFlag); COPY_FLAG(inspect, Py_InspectFlag); COPY_FLAG(interactive, Py_InteractiveFlag); @@ -924,7 +923,7 @@ config_wstr_to_int(const wchar_t *wstr, int *result) static _PyInitError config_read_env_vars(_PyCoreConfig *config) { - int use_env = config->preconfig.use_environment; + int use_env = config->use_environment; /* Get environment variables */ _Py_get_env_flag(use_env, &config->parser_debug, "PYTHONDEBUG"); @@ -1149,7 +1148,8 @@ get_locale_encoding(char **locale_encoding) static _PyInitError -config_init_stdio_encoding(_PyCoreConfig *config) +config_init_stdio_encoding(_PyCoreConfig *config, + const _PyPreConfig *preconfig) { /* If Py_SetStandardStreamEncoding() have been called, use these parameters. */ @@ -1219,7 +1219,7 @@ config_init_stdio_encoding(_PyCoreConfig *config) } /* UTF-8 Mode uses UTF-8/surrogateescape */ - if (config->preconfig.utf8_mode) { + if (preconfig->utf8_mode) { if (config->stdio_encoding == NULL) { config->stdio_encoding = _PyMem_RawStrdup("utf-8"); if (config->stdio_encoding == NULL) { @@ -1254,10 +1254,10 @@ config_init_stdio_encoding(_PyCoreConfig *config) static _PyInitError -config_init_fs_encoding(_PyCoreConfig *config) +config_init_fs_encoding(_PyCoreConfig *config, const _PyPreConfig *preconfig) { #ifdef MS_WINDOWS - if (config->preconfig.legacy_windows_fs_encoding) { + if (preconfig->legacy_windows_fs_encoding) { /* Legacy Windows filesystem encoding: mbcs/replace */ if (config->filesystem_encoding == NULL) { config->filesystem_encoding = _PyMem_RawStrdup("mbcs"); @@ -1292,7 +1292,7 @@ config_init_fs_encoding(_PyCoreConfig *config) } #else if (config->filesystem_encoding == NULL) { - if (config->preconfig.utf8_mode) { + if (preconfig->utf8_mode) { /* UTF-8 Mode use: utf-8/surrogateescape */ config->filesystem_encoding = _PyMem_RawStrdup("utf-8"); /* errors defaults to surrogateescape above */ @@ -1341,12 +1341,8 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; - err = _Py_PreInitializeFromConfig(config); - if (_Py_INIT_FAILED(err)) { - return err; - } - - _PyPreCmdline_GetPreConfig(cmdline, &_PyRuntime.preconfig); + const _PyPreConfig *preconfig = &_PyRuntime.preconfig; + _PyPreCmdline_GetPreConfig(cmdline, preconfig); _PyPreCmdline_GetCoreConfig(cmdline, config); err = _PyPreCmdline_Read(cmdline); @@ -1360,19 +1356,16 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) return _Py_INIT_NO_MEMORY(); } - if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) { - return _Py_INIT_NO_MEMORY(); - } - _PyCoreConfig_GetGlobalConfig(config); - assert(config->preconfig.use_environment >= 0); + assert(config->use_environment >= 0); - if (config->preconfig.isolated > 0) { + if (config->isolated > 0) { + config->use_environment = 0; config->user_site_directory = 0; } - if (config->preconfig.use_environment) { + if (config->use_environment) { err = config_read_env_vars(config); if (_Py_INIT_FAILED(err)) { return err; @@ -1421,7 +1414,7 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) } /* default values */ - if (config->preconfig.dev_mode) { + if (config->dev_mode) { if (config->faulthandler < 0) { config->faulthandler = 1; } @@ -1438,13 +1431,13 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) } if (config->filesystem_encoding == NULL || config->filesystem_errors == NULL) { - err = config_init_fs_encoding(config); + err = config_init_fs_encoding(config, preconfig); if (_Py_INIT_FAILED(err)) { return err; } } - err = config_init_stdio_encoding(config); + err = config_init_stdio_encoding(config, preconfig); if (_Py_INIT_FAILED(err)) { return err; } @@ -1456,7 +1449,7 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) } } - assert(config->preconfig.use_environment >= 0); + assert(config->use_environment >= 0); assert(config->filesystem_encoding != NULL); assert(config->filesystem_errors != NULL); assert(config->stdio_encoding != NULL); @@ -1544,22 +1537,11 @@ config_init_stdio(const _PyCoreConfig *config) - set Py_xxx global configuration variables - initialize C standard streams (stdin, stdout, stderr) */ -_PyInitError +void _PyCoreConfig_Write(const _PyCoreConfig *config) { _PyCoreConfig_SetGlobalConfig(config); config_init_stdio(config); - - /* Write the new pre-configuration into _PyRuntime */ - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - int res = _PyPreConfig_Copy(&_PyRuntime.preconfig, &config->preconfig); - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - if (res < 0) { - return _Py_INIT_NO_MEMORY(); - } - - return _Py_INIT_OK(); } @@ -1604,6 +1586,9 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config) #define SET_ITEM_WSTRLIST(LIST) \ SET_ITEM(#LIST, _PyWstrList_AsList(&config->LIST)) + SET_ITEM_INT(isolated); + SET_ITEM_INT(use_environment); + SET_ITEM_INT(dev_mode); SET_ITEM_INT(install_signal_handlers); SET_ITEM_INT(use_hash_seed); SET_ITEM_UINT(hash_seed); @@ -1945,7 +1930,7 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) * the lowest precedence entries first so that later entries override them. */ - if (config->preconfig.dev_mode) { + if (config->dev_mode) { if (_PyWstrList_Append(&config->warnoptions, L"default")) { return _Py_INIT_NO_MEMORY(); } @@ -2101,7 +2086,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) return err; } - if (config->preconfig.use_environment) { + if (config->use_environment) { err = cmdline_init_env_warnoptions(cmdline, config); if (_Py_INIT_FAILED(err)) { return err; @@ -2178,8 +2163,7 @@ _Py_GetConfigsAsDict(void) /* pre config */ PyInterpreterState *interp = _PyInterpreterState_Get(); - const _PyCoreConfig *core_config = _PyInterpreterState_GetCoreConfig(interp); - const _PyPreConfig *pre_config = &core_config->preconfig; + const _PyPreConfig *pre_config = &_PyRuntime.preconfig; dict = _PyPreConfig_AsDict(pre_config); if (dict == NULL) { goto error; @@ -2190,6 +2174,7 @@ _Py_GetConfigsAsDict(void) Py_CLEAR(dict); /* core config */ + const _PyCoreConfig *core_config = _PyInterpreterState_GetCoreConfig(interp); dict = _PyCoreConfig_AsDict(core_config); if (dict == NULL) { goto error; diff --git a/Python/pathconfig.c b/Python/pathconfig.c index f0b13fd1b0..7fea7c3667 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -331,7 +331,7 @@ _PyCoreConfig_CalculatePathConfig(_PyCoreConfig *config) #endif if (path_config.isolated != -1) { - config->preconfig.isolated = path_config.isolated; + config->isolated = path_config.isolated; } if (path_config.site_import != -1) { config->site_import = path_config.site_import; diff --git a/Python/preconfig.c b/Python/preconfig.c index 8b685ce42d..d336352d93 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -143,6 +143,23 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(dev_mode); + +#undef COPY_ATTR +} + + +void +_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (cmdline->ATTR != -1) { \ + config->ATTR = cmdline->ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + COPY_ATTR(dev_mode); #undef COPY_ATTR } @@ -152,12 +169,13 @@ void _PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config) { #define COPY_ATTR(ATTR) \ - if (config->preconfig.ATTR != -1) { \ - cmdline->ATTR = config->preconfig.ATTR; \ + if (config->ATTR != -1) { \ + cmdline->ATTR = config->ATTR; \ } COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(dev_mode); #undef COPY_ATTR } @@ -167,12 +185,13 @@ void _PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config) { #define COPY_ATTR(ATTR) \ - if (config->preconfig.ATTR == -1 && cmdline->ATTR != -1) { \ - config->preconfig.ATTR = cmdline->ATTR; \ + if (config->ATTR == -1 && cmdline->ATTR != -1) { \ + config->ATTR = cmdline->ATTR; \ } COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(dev_mode); #undef COPY_ATTR } @@ -206,13 +225,13 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2) COPY_ATTR(isolated); COPY_ATTR(use_environment); + COPY_ATTR(dev_mode); COPY_ATTR(coerce_c_locale); COPY_ATTR(coerce_c_locale_warn); #ifdef MS_WINDOWS COPY_ATTR(legacy_windows_fs_encoding); #endif COPY_ATTR(utf8_mode); - COPY_ATTR(dev_mode); COPY_STR_ATTR(allocator); #undef COPY_ATTR @@ -567,21 +586,6 @@ get_ctype_locale(char **locale_p) } -void -_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) -{ -#define COPY_ATTR(ATTR) \ - if (cmdline->ATTR != -1) { \ - config->ATTR = cmdline->ATTR; \ - } - - COPY_ATTR(use_environment); - COPY_ATTR(isolated); - -#undef COPY_ATTR -} - - PyObject* _PyPreConfig_AsDict(const _PyPreConfig *config) { @@ -712,7 +716,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, if (coreconfig) { _PyPreCmdline_GetCoreConfig(&cmdline, coreconfig); if (config->dev_mode == -1) { - config->dev_mode = coreconfig->preconfig.dev_mode; + config->dev_mode = coreconfig->dev_mode; } } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index e08f290d8d..b12fa820e9 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -286,9 +286,10 @@ static const char *_C_LOCALE_WARNING = "locales is recommended.\n"; static void -_emit_stderr_warning_for_legacy_locale(const _PyCoreConfig *core_config) +_emit_stderr_warning_for_legacy_locale(void) { - if (core_config->preconfig.coerce_c_locale_warn && _Py_LegacyLocaleDetected()) { + const _PyPreConfig *preconfig = &_PyRuntime.preconfig; + if (preconfig->coerce_c_locale_warn && _Py_LegacyLocaleDetected()) { PySys_FormatStderr("%s", _C_LOCALE_WARNING); } } @@ -675,6 +676,8 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, { PyInterpreterState *interp; + _PyCoreConfig_Write(core_config); + _PyInitError err = pycore_init_runtime(core_config); if (_Py_INIT_FAILED(err)) { return err; @@ -720,54 +723,64 @@ pyinit_preinit(_PyPreConfig *config, const _PyCoreConfig *coreconfig) { _PyInitError err; + _PyPreConfig local_config = _PyPreConfig_INIT; + if (!config) { + config = &local_config; + } err = _PyRuntime_Initialize(); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } if (_PyRuntime.pre_initialized) { /* If it's already configured: ignored the new configuration */ - return _Py_INIT_OK(); - } - - if (!src_config && coreconfig) { - src_config = &coreconfig->preconfig; + err = _Py_INIT_OK(); + goto done; } if (src_config) { if (_PyPreConfig_Copy(config, src_config) < 0) { - return _Py_INIT_ERR("failed to copy pre config"); + err = _Py_INIT_ERR("failed to copy pre config"); + goto done; } } err = _PyPreConfig_Read(config, NULL, coreconfig); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } err = _PyPreConfig_Write(config); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } _PyRuntime.pre_initialized = 1; - return _Py_INIT_OK(); + err = _Py_INIT_OK(); + +done: + _PyPreConfig_Clear(&local_config); + return err; } _PyInitError _Py_PreInitialize(void) { - _PyPreConfig config = _PyPreConfig_INIT; - _PyInitError err = pyinit_preinit(&config, NULL, NULL); - _PyPreConfig_Clear(&config); - return err; + return pyinit_preinit(NULL, NULL, NULL); } _PyInitError -_Py_PreInitializeFromPreConfig(_PyPreConfig *config) +_Py_PreInitializeFromPreConfig(const _PyPreConfig *src_config) +{ + return pyinit_preinit(NULL, src_config, NULL); +} + + +_PyInitError +_Py_PreInitializeInPlace(_PyPreConfig *config) { return pyinit_preinit(config, NULL, NULL); } @@ -776,10 +789,7 @@ _Py_PreInitializeFromPreConfig(_PyPreConfig *config) _PyInitError _Py_PreInitializeFromConfig(const _PyCoreConfig *coreconfig) { - _PyPreConfig config = _PyPreConfig_INIT; - _PyInitError err = pyinit_preinit(&config, NULL, coreconfig); - _PyPreConfig_Clear(&config); - return err; + return pyinit_preinit(NULL, NULL, coreconfig); } @@ -964,7 +974,7 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp, } #ifndef MS_WINDOWS - _emit_stderr_warning_for_legacy_locale(core_config); + _emit_stderr_warning_for_legacy_locale(); #endif return _Py_INIT_OK(); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 3df4d44a7c..12ec7d5918 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2158,6 +2158,7 @@ make_flags(void) { int pos = 0; PyObject *seq; + const _PyPreConfig *preconfig = &_PyRuntime.preconfig; const _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config; seq = PyStructSequence_New(&FlagsType); @@ -2174,16 +2175,16 @@ make_flags(void) SetFlag(!config->write_bytecode); SetFlag(!config->user_site_directory); SetFlag(!config->site_import); - SetFlag(!config->preconfig.use_environment); + SetFlag(!config->use_environment); SetFlag(config->verbose); /* SetFlag(saw_unbuffered_flag); */ /* SetFlag(skipfirstline); */ SetFlag(config->bytes_warning); SetFlag(config->quiet); SetFlag(config->use_hash_seed == 0 || config->hash_seed != 0); - SetFlag(config->preconfig.isolated); - PyStructSequence_SET_ITEM(seq, pos++, PyBool_FromLong(config->preconfig.dev_mode)); - SetFlag(config->preconfig.utf8_mode); + SetFlag(config->isolated); + PyStructSequence_SET_ITEM(seq, pos++, PyBool_FromLong(config->dev_mode)); + SetFlag(preconfig->utf8_mode); #undef SetFlag if (PyErr_Occurred()) { -- cgit v1.2.1 From f8ba6f5afc317d1be3025db1be410ac66a7e5a27 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Mar 2019 16:58:50 +0100 Subject: bpo-36301: Cleanup preconfig.c and coreconfig.c (GH-12563) * _PyCoreConfig_Write() now updates _PyRuntime.preconfig * Remove _PyPreCmdline_Copy() * _PyPreCmdline_Read() now accepts _PyPreConfig and _PyCoreConfig optional configurations. * Rename _PyPreConfig_ReadFromArgv() to _PyPreConfig_Read(). Simplify the code. * Calling _PyCoreConfig_Read() no longer adds the warning options twice: don't add a warning option if it's already in the list. * Rename _PyCoreConfig_ReadFromArgv() to _PyCoreConfig_Read(). * Rename config_from_cmdline() to _PyCoreConfig_ReadFromArgv(). * Add more assertions on _PyCoreConfig in _PyCoreConfig_Read(). * Move some functions. * Make some config functions private. --- Python/coreconfig.c | 574 +++++++++++++++++++++++++----------------------- Python/pathconfig.c | 2 +- Python/preconfig.c | 603 ++++++++++++++++++++++++--------------------------- Python/pylifecycle.c | 16 +- 4 files changed, 587 insertions(+), 608 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 2e6eb40298..2f54e79081 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -296,7 +296,7 @@ _PyWstrList_Append(_PyWstrList *list, const wchar_t *item) } -static int +int _PyWstrList_Extend(_PyWstrList *list, const _PyWstrList *list2) { for (Py_ssize_t i = 0; i < list2->length; i++) { @@ -308,6 +308,18 @@ _PyWstrList_Extend(_PyWstrList *list, const _PyWstrList *list2) } +static int +_PyWstrList_Find(_PyWstrList *list, const wchar_t *item) +{ + for (Py_ssize_t i = 0; i < list->length; i++) { + if (wcscmp(list->items[i], item) == 0) { + return 1; + } + } + return 0; +} + + PyObject* _PyWstrList_AsList(const _PyWstrList *list) { @@ -607,6 +619,120 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) } +static PyObject * +_PyCoreConfig_AsDict(const _PyCoreConfig *config) +{ + PyObject *dict; + + dict = PyDict_New(); + if (dict == NULL) { + return NULL; + } + +#define SET_ITEM(KEY, EXPR) \ + do { \ + PyObject *obj = (EXPR); \ + if (obj == NULL) { \ + goto fail; \ + } \ + int res = PyDict_SetItemString(dict, (KEY), obj); \ + Py_DECREF(obj); \ + if (res < 0) { \ + goto fail; \ + } \ + } while (0) +#define FROM_STRING(STR) \ + ((STR != NULL) ? \ + PyUnicode_FromString(STR) \ + : (Py_INCREF(Py_None), Py_None)) +#define SET_ITEM_INT(ATTR) \ + SET_ITEM(#ATTR, PyLong_FromLong(config->ATTR)) +#define SET_ITEM_UINT(ATTR) \ + SET_ITEM(#ATTR, PyLong_FromUnsignedLong(config->ATTR)) +#define SET_ITEM_STR(ATTR) \ + SET_ITEM(#ATTR, FROM_STRING(config->ATTR)) +#define FROM_WSTRING(STR) \ + ((STR != NULL) ? \ + PyUnicode_FromWideChar(STR, -1) \ + : (Py_INCREF(Py_None), Py_None)) +#define SET_ITEM_WSTR(ATTR) \ + SET_ITEM(#ATTR, FROM_WSTRING(config->ATTR)) +#define SET_ITEM_WSTRLIST(LIST) \ + SET_ITEM(#LIST, _PyWstrList_AsList(&config->LIST)) + + SET_ITEM_INT(isolated); + SET_ITEM_INT(use_environment); + SET_ITEM_INT(dev_mode); + SET_ITEM_INT(install_signal_handlers); + SET_ITEM_INT(use_hash_seed); + SET_ITEM_UINT(hash_seed); + SET_ITEM_INT(faulthandler); + SET_ITEM_INT(tracemalloc); + SET_ITEM_INT(import_time); + SET_ITEM_INT(show_ref_count); + SET_ITEM_INT(show_alloc_count); + SET_ITEM_INT(dump_refs); + SET_ITEM_INT(malloc_stats); + SET_ITEM_STR(filesystem_encoding); + SET_ITEM_STR(filesystem_errors); + SET_ITEM_WSTR(pycache_prefix); + SET_ITEM_WSTR(program_name); + SET_ITEM_WSTRLIST(argv); + SET_ITEM_WSTR(program); + SET_ITEM_WSTRLIST(xoptions); + SET_ITEM_WSTRLIST(warnoptions); + SET_ITEM_WSTR(module_search_path_env); + SET_ITEM_WSTR(home); + SET_ITEM_WSTRLIST(module_search_paths); + SET_ITEM_WSTR(executable); + SET_ITEM_WSTR(prefix); + SET_ITEM_WSTR(base_prefix); + SET_ITEM_WSTR(exec_prefix); + SET_ITEM_WSTR(base_exec_prefix); +#ifdef MS_WINDOWS + SET_ITEM_WSTR(dll_path); +#endif + SET_ITEM_INT(site_import); + SET_ITEM_INT(bytes_warning); + SET_ITEM_INT(inspect); + SET_ITEM_INT(interactive); + SET_ITEM_INT(optimization_level); + SET_ITEM_INT(parser_debug); + SET_ITEM_INT(write_bytecode); + SET_ITEM_INT(verbose); + SET_ITEM_INT(quiet); + SET_ITEM_INT(user_site_directory); + SET_ITEM_INT(buffered_stdio); + SET_ITEM_STR(stdio_encoding); + SET_ITEM_STR(stdio_errors); +#ifdef MS_WINDOWS + SET_ITEM_INT(legacy_windows_stdio); +#endif + SET_ITEM_INT(skip_source_first_line); + SET_ITEM_WSTR(run_command); + SET_ITEM_WSTR(run_module); + SET_ITEM_WSTR(run_filename); + SET_ITEM_INT(_install_importlib); + SET_ITEM_STR(_check_hash_pycs_mode); + SET_ITEM_INT(_frozen); + + return dict; + +fail: + Py_DECREF(dict); + return NULL; + +#undef FROM_STRING +#undef FROM_WSTRING +#undef SET_ITEM +#undef SET_ITEM_INT +#undef SET_ITEM_UINT +#undef SET_ITEM_STR +#undef SET_ITEM_WSTR +#undef SET_ITEM_WSTRLIST +} + + static const char* _PyCoreConfig_GetEnv(const _PyCoreConfig *config, const char *name) { @@ -614,6 +740,9 @@ _PyCoreConfig_GetEnv(const _PyCoreConfig *config, const char *name) } +/* Get a copy of the environment variable as wchar_t*. + Return 0 on success, but *dest can be NULL. + Return -1 on memory allocation failure. Return -2 on decoding error. */ static int _PyCoreConfig_GetEnvDup(const _PyCoreConfig *config, wchar_t **dest, @@ -662,7 +791,7 @@ _PyCoreConfig_GetEnvDup(const _PyCoreConfig *config, } -void +static void _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config) { #define COPY_FLAG(ATTR, VALUE) \ @@ -699,7 +828,7 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config) /* Set Py_xxx global configuration variables from 'config' configuration. */ -void +static void _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config) { #define COPY_FLAG(ATTR, VAR) \ @@ -848,10 +977,10 @@ config_get_xoption(const _PyCoreConfig *config, wchar_t *name) static _PyInitError config_init_home(_PyCoreConfig *config) { - wchar_t *home; + assert(config->home == NULL); /* If Py_SetPythonHome() was called, use its value */ - home = _Py_path_config.home; + wchar_t *home = _Py_path_config.home; if (home) { config->home = _PyMem_RawWcsdup(home); if (config->home == NULL) { @@ -1098,7 +1227,7 @@ config_read_complex_options(_PyCoreConfig *config) static const char * -get_stdio_errors(const _PyCoreConfig *config) +config_get_stdio_errors(const _PyCoreConfig *config) { #ifndef MS_WINDOWS const char *loc = setlocale(LC_CTYPE, NULL); @@ -1125,7 +1254,7 @@ get_stdio_errors(const _PyCoreConfig *config) static _PyInitError -get_locale_encoding(char **locale_encoding) +config_get_locale_encoding(char **locale_encoding) { #ifdef MS_WINDOWS char encoding[20]; @@ -1236,13 +1365,13 @@ config_init_stdio_encoding(_PyCoreConfig *config, /* Choose the default error handler based on the current locale. */ if (config->stdio_encoding == NULL) { - _PyInitError err = get_locale_encoding(&config->stdio_encoding); + _PyInitError err = config_get_locale_encoding(&config->stdio_encoding); if (_Py_INIT_FAILED(err)) { return err; } } if (config->stdio_errors == NULL) { - const char *errors = get_stdio_errors(config); + const char *errors = config_get_stdio_errors(config); config->stdio_errors = _PyMem_RawStrdup(errors); if (config->stdio_errors == NULL) { return _Py_INIT_NO_MEMORY(); @@ -1306,7 +1435,7 @@ config_init_fs_encoding(_PyCoreConfig *config, const _PyPreConfig *preconfig) #if defined(__APPLE__) || defined(__ANDROID__) config->filesystem_encoding = _PyMem_RawStrdup("utf-8"); #else - _PyInitError err = get_locale_encoding(&config->filesystem_encoding); + _PyInitError err = config_get_locale_encoding(&config->filesystem_encoding); if (_Py_INIT_FAILED(err)) { return err; } @@ -1330,38 +1459,22 @@ config_init_fs_encoding(_PyCoreConfig *config, const _PyPreConfig *preconfig) } -/* Read the configuration into _PyCoreConfig from: - - * Environment variables - * Py_xxx global configuration variables - - See _PyCoreConfig_ReadFromArgv() to parse also command line arguments. */ static _PyInitError -config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) +config_read(_PyCoreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; const _PyPreConfig *preconfig = &_PyRuntime.preconfig; - _PyPreCmdline_GetPreConfig(cmdline, preconfig); - _PyPreCmdline_GetCoreConfig(cmdline, config); - - err = _PyPreCmdline_Read(cmdline); + err = _PyPreCmdline_Read(cmdline, preconfig, config); if (_Py_INIT_FAILED(err)) { return err; } - _PyPreCmdline_SetCoreConfig(cmdline, config); - - if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) { + if (_PyPreCmdline_SetCoreConfig(cmdline, config) < 0) { return _Py_INIT_NO_MEMORY(); } - _PyCoreConfig_GetGlobalConfig(config); - - assert(config->use_environment >= 0); - if (config->isolated > 0) { - config->use_environment = 0; config->user_site_directory = 0; } @@ -1419,16 +1532,16 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) config->faulthandler = 1; } } - if (config->use_hash_seed < 0) { - config->use_hash_seed = 0; - config->hash_seed = 0; - } if (config->faulthandler < 0) { config->faulthandler = 0; } if (config->tracemalloc < 0) { config->tracemalloc = 0; } + if (config->use_hash_seed < 0) { + config->use_hash_seed = 0; + config->hash_seed = 0; + } if (config->filesystem_encoding == NULL || config->filesystem_errors == NULL) { err = config_init_fs_encoding(config, preconfig); @@ -1449,53 +1562,10 @@ config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) } } - assert(config->use_environment >= 0); - assert(config->filesystem_encoding != NULL); - assert(config->filesystem_errors != NULL); - assert(config->stdio_encoding != NULL); - assert(config->stdio_errors != NULL); - assert(config->_check_hash_pycs_mode != NULL); - assert(_PyWstrList_CheckConsistency(&config->argv)); - return _Py_INIT_OK(); } -static _PyInitError -config_read(_PyCoreConfig *config, const _PyPreCmdline *src_cmdline) -{ - _PyInitError err; - - err = _Py_PreInitializeFromConfig(config); - if (_Py_INIT_FAILED(err)) { - return err; - } - - _PyPreCmdline cmdline = _PyPreCmdline_INIT; - - if (src_cmdline) { - if (_PyPreCmdline_Copy(&cmdline, src_cmdline) < 0) { - err = _Py_INIT_NO_MEMORY(); - goto done; - } - } - - err = config_read_impl(config, &cmdline); - -done: - _PyPreCmdline_Clear(&cmdline); - return err; - -} - - -_PyInitError -_PyCoreConfig_Read(_PyCoreConfig *config) -{ - return config_read(config, NULL); -} - - static void config_init_stdio(const _PyCoreConfig *config) { @@ -1542,139 +1612,30 @@ _PyCoreConfig_Write(const _PyCoreConfig *config) { _PyCoreConfig_SetGlobalConfig(config); config_init_stdio(config); -} - - -static PyObject * -_PyCoreConfig_AsDict(const _PyCoreConfig *config) -{ - PyObject *dict; - - dict = PyDict_New(); - if (dict == NULL) { - return NULL; - } -#define SET_ITEM(KEY, EXPR) \ - do { \ - PyObject *obj = (EXPR); \ - if (obj == NULL) { \ - goto fail; \ - } \ - int res = PyDict_SetItemString(dict, (KEY), obj); \ - Py_DECREF(obj); \ - if (res < 0) { \ - goto fail; \ - } \ - } while (0) -#define FROM_STRING(STR) \ - ((STR != NULL) ? \ - PyUnicode_FromString(STR) \ - : (Py_INCREF(Py_None), Py_None)) -#define SET_ITEM_INT(ATTR) \ - SET_ITEM(#ATTR, PyLong_FromLong(config->ATTR)) -#define SET_ITEM_UINT(ATTR) \ - SET_ITEM(#ATTR, PyLong_FromUnsignedLong(config->ATTR)) -#define SET_ITEM_STR(ATTR) \ - SET_ITEM(#ATTR, FROM_STRING(config->ATTR)) -#define FROM_WSTRING(STR) \ - ((STR != NULL) ? \ - PyUnicode_FromWideChar(STR, -1) \ - : (Py_INCREF(Py_None), Py_None)) -#define SET_ITEM_WSTR(ATTR) \ - SET_ITEM(#ATTR, FROM_WSTRING(config->ATTR)) -#define SET_ITEM_WSTRLIST(LIST) \ - SET_ITEM(#LIST, _PyWstrList_AsList(&config->LIST)) - - SET_ITEM_INT(isolated); - SET_ITEM_INT(use_environment); - SET_ITEM_INT(dev_mode); - SET_ITEM_INT(install_signal_handlers); - SET_ITEM_INT(use_hash_seed); - SET_ITEM_UINT(hash_seed); - SET_ITEM_INT(faulthandler); - SET_ITEM_INT(tracemalloc); - SET_ITEM_INT(import_time); - SET_ITEM_INT(show_ref_count); - SET_ITEM_INT(show_alloc_count); - SET_ITEM_INT(dump_refs); - SET_ITEM_INT(malloc_stats); - SET_ITEM_STR(filesystem_encoding); - SET_ITEM_STR(filesystem_errors); - SET_ITEM_WSTR(pycache_prefix); - SET_ITEM_WSTR(program_name); - SET_ITEM_WSTRLIST(argv); - SET_ITEM_WSTR(program); - SET_ITEM_WSTRLIST(xoptions); - SET_ITEM_WSTRLIST(warnoptions); - SET_ITEM_WSTR(module_search_path_env); - SET_ITEM_WSTR(home); - SET_ITEM_WSTRLIST(module_search_paths); - SET_ITEM_WSTR(executable); - SET_ITEM_WSTR(prefix); - SET_ITEM_WSTR(base_prefix); - SET_ITEM_WSTR(exec_prefix); - SET_ITEM_WSTR(base_exec_prefix); -#ifdef MS_WINDOWS - SET_ITEM_WSTR(dll_path); -#endif - SET_ITEM_INT(site_import); - SET_ITEM_INT(bytes_warning); - SET_ITEM_INT(inspect); - SET_ITEM_INT(interactive); - SET_ITEM_INT(optimization_level); - SET_ITEM_INT(parser_debug); - SET_ITEM_INT(write_bytecode); - SET_ITEM_INT(verbose); - SET_ITEM_INT(quiet); - SET_ITEM_INT(user_site_directory); - SET_ITEM_INT(buffered_stdio); - SET_ITEM_STR(stdio_encoding); - SET_ITEM_STR(stdio_errors); -#ifdef MS_WINDOWS - SET_ITEM_INT(legacy_windows_stdio); -#endif - SET_ITEM_INT(skip_source_first_line); - SET_ITEM_WSTR(run_command); - SET_ITEM_WSTR(run_module); - SET_ITEM_WSTR(run_filename); - SET_ITEM_INT(_install_importlib); - SET_ITEM_STR(_check_hash_pycs_mode); - SET_ITEM_INT(_frozen); - - return dict; - -fail: - Py_DECREF(dict); - return NULL; - -#undef FROM_STRING -#undef FROM_WSTRING -#undef SET_ITEM -#undef SET_ITEM_INT -#undef SET_ITEM_UINT -#undef SET_ITEM_STR -#undef SET_ITEM_WSTR -#undef SET_ITEM_WSTRLIST + /* Write the new pre-configuration into _PyRuntime */ + _PyPreConfig *preconfig = &_PyRuntime.preconfig; + preconfig->isolated = config->isolated; + preconfig->use_environment = config->use_environment; + preconfig->dev_mode = config->dev_mode; } /* --- _PyCmdline ------------------------------------------------- */ typedef struct { - _PyPreCmdline precmdline; - _PyWstrList warnoptions; /* Command line -W options */ + _PyWstrList cmdline_warnoptions; /* Command line -W options */ _PyWstrList env_warnoptions; /* PYTHONWARNINGS environment variables */ int print_help; /* -h, -? options */ int print_version; /* -V option */ + int need_usage; } _PyCmdline; static void cmdline_clear(_PyCmdline *cmdline) { - _PyPreCmdline_Clear(&cmdline->precmdline); - _PyWstrList_Clear(&cmdline->warnoptions); + _PyWstrList_Clear(&cmdline->cmdline_warnoptions); _PyWstrList_Clear(&cmdline->env_warnoptions); } @@ -1684,9 +1645,9 @@ cmdline_clear(_PyCmdline *cmdline) /* Parse the command line arguments */ static _PyInitError config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, - int *need_usage) + _PyPreCmdline *precmdline) { - const _PyWstrList *argv = &cmdline->precmdline.argv; + const _PyWstrList *argv = &precmdline->argv; _PyOS_ResetGetOpt(); do { @@ -1740,7 +1701,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, } else { fprintf(stderr, "--check-hash-based-pycs must be one of " "'default', 'always', or 'never'\n"); - *need_usage = 1; + cmdline->need_usage = 1; return _Py_INIT_OK(); } break; @@ -1761,7 +1722,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, case 'E': case 'I': case 'X': - /* option handled by _PyPreConfig_ReadFromArgv() */ + /* option handled by _PyPreCmdline_Read() */ break; /* case 'J': reserved for Jython */ @@ -1808,7 +1769,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, break; case 'W': - if (_PyWstrList_Append(&cmdline->warnoptions, _PyOS_optarg) < 0) { + if (_PyWstrList_Append(&cmdline->cmdline_warnoptions, _PyOS_optarg) < 0) { return _Py_INIT_NO_MEMORY(); } break; @@ -1825,7 +1786,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, default: /* unknown argument: parsing failed */ - *need_usage = 1; + cmdline->need_usage = 1; return _Py_INIT_OK(); } } while (1); @@ -1891,9 +1852,9 @@ cmdline_init_env_warnoptions(_PyCmdline *cmdline, const _PyCoreConfig *config) static _PyInitError -config_init_program(_PyCoreConfig *config, const _PyCmdline *cmdline) +config_init_program(_PyCoreConfig *config, const _PyPreCmdline *cmdline) { - const _PyWstrList *argv = &cmdline->precmdline.argv; + const _PyWstrList *argv = &cmdline->argv; wchar_t *program; if (argv->length >= 1) { program = argv->items[0]; @@ -1910,11 +1871,23 @@ config_init_program(_PyCoreConfig *config, const _PyCmdline *cmdline) } +static int +config_add_warnoption(_PyCoreConfig *config, const wchar_t *option) +{ + if (_PyWstrList_Find(&config->warnoptions, option)) { + /* Already present: do nothing */ + return 0; + } + if (_PyWstrList_Append(&config->warnoptions, option)) { + return -1; + } + return 0; +} + + static _PyInitError config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) { - assert(config->warnoptions.length == 0); - /* The priority order for warnings configuration is (highest precedence * first): * @@ -1931,17 +1904,26 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) */ if (config->dev_mode) { - if (_PyWstrList_Append(&config->warnoptions, L"default")) { + if (config_add_warnoption(config, L"default") < 0) { return _Py_INIT_NO_MEMORY(); } } - if (_PyWstrList_Extend(&config->warnoptions, &cmdline->env_warnoptions) < 0) { - return _Py_INIT_NO_MEMORY(); + Py_ssize_t i; + const _PyWstrList *options; + + options = &cmdline->env_warnoptions; + for (i = 0; i < options->length; i++) { + if (config_add_warnoption(config, options->items[i]) < 0) { + return _Py_INIT_NO_MEMORY(); + } } - if (_PyWstrList_Extend(&config->warnoptions, &cmdline->warnoptions) < 0) { - return _Py_INIT_NO_MEMORY(); + options = &cmdline->cmdline_warnoptions; + for (i = 0; i < options->length; i++) { + if (config_add_warnoption(config, options->items[i]) < 0) { + return _Py_INIT_NO_MEMORY(); + } } /* If the bytes_warning_flag isn't set, bytesobject.c and bytearrayobject.c @@ -1956,7 +1938,7 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) else { filter = L"default::BytesWarning"; } - if (_PyWstrList_Append(&config->warnoptions, filter)) { + if (config_add_warnoption(config, filter) < 0) { return _Py_INIT_NO_MEMORY(); } } @@ -1965,9 +1947,9 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline) static _PyInitError -config_init_argv(_PyCoreConfig *config, const _PyCmdline *cmdline) +config_init_argv(_PyCoreConfig *config, const _PyPreCmdline *cmdline) { - const _PyWstrList *cmdline_argv = &cmdline->precmdline.argv; + const _PyWstrList *cmdline_argv = &cmdline->argv; _PyWstrList config_argv = _PyWstrList_INIT; /* Copy argv to be able to modify it (to force -c/-m) */ @@ -2032,110 +2014,152 @@ config_usage(int error, const wchar_t* program) } -/* Parse command line options and environment variables. */ -static _PyInitError -config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) +/* Read the configuration into _PyCoreConfig from: + + * Command line arguments + * Environment variables + * Py_xxx global configuration variables */ +_PyInitError +_PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) { - int need_usage = 0; _PyInitError err; + err = _Py_PreInitializeFromConfig(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + _PyCoreConfig_GetGlobalConfig(config); + _PyPreCmdline precmdline = _PyPreCmdline_INIT; + if (args) { + err = _PyPreCmdline_SetArgv(&precmdline, args); + if (_Py_INIT_FAILED(err)) { + goto done; + } + } + if (config->program == NULL) { - err = config_init_program(config, cmdline); + err = config_init_program(config, &precmdline); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } } - err = _PyPreCmdline_Read(&cmdline->precmdline); + const _PyPreConfig *preconfig = &_PyRuntime.preconfig; + err = _PyPreCmdline_Read(&precmdline, preconfig, config); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } - _PyPreCmdline_SetPreConfig(&cmdline->precmdline, &_PyRuntime.preconfig); + _PyCmdline cmdline; + memset(&cmdline, 0, sizeof(cmdline)); - err = config_parse_cmdline(config, cmdline, &need_usage); - if (_Py_INIT_FAILED(err)) { - return err; - } + if (args) { + err = config_parse_cmdline(config, &cmdline, &precmdline); + if (_Py_INIT_FAILED(err)) { + goto done; + } - if (need_usage) { - config_usage(1, config->program); - return _Py_INIT_EXIT(2); - } + if (cmdline.need_usage) { + config_usage(1, config->program); + err = _Py_INIT_EXIT(2); + goto done; + } - if (cmdline->print_help) { - config_usage(0, config->program); - return _Py_INIT_EXIT(0); - } + if (cmdline.print_help) { + config_usage(0, config->program); + err = _Py_INIT_EXIT(0); + goto done; + } - if (cmdline->print_version) { - printf("Python %s\n", - (cmdline->print_version >= 2) ? Py_GetVersion() : PY_VERSION); - return _Py_INIT_EXIT(0); - } + if (cmdline.print_version) { + printf("Python %s\n", + (cmdline.print_version >= 2) ? Py_GetVersion() : PY_VERSION); + err = _Py_INIT_EXIT(0); + goto done; + } - err = config_init_argv(config, cmdline); - if (_Py_INIT_FAILED(err)) { - return err; + err = config_init_argv(config, &precmdline); + if (_Py_INIT_FAILED(err)) { + goto done; + } } - err = config_read(config, &cmdline->precmdline); + err = config_read(config, &precmdline); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } if (config->use_environment) { - err = cmdline_init_env_warnoptions(cmdline, config); + err = cmdline_init_env_warnoptions(&cmdline, config); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } } - err = config_init_warnoptions(config, cmdline); + err = config_init_warnoptions(config, &cmdline); if (_Py_INIT_FAILED(err)) { - return err; + goto done; } - const _PyWstrList *argv = &cmdline->precmdline.argv; + const _PyWstrList *argv = &precmdline.argv; if (_Py_SetArgcArgv(argv->length, argv->items) < 0) { - return _Py_INIT_NO_MEMORY(); - } - return _Py_INIT_OK(); -} - - -/* Read the configuration into _PyCoreConfig from: - - * Command line arguments - * Environment variables - * Py_xxx global configuration variables */ -_PyInitError -_PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args) -{ - _PyInitError err; - - err = _Py_PreInitializeFromConfig(config); - if (_Py_INIT_FAILED(err)) { - return err; - } - - _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT}; - - err = _PyPreCmdline_SetArgv(&cmdline.precmdline, args); - if (_Py_INIT_FAILED(err)) { + err = _Py_INIT_NO_MEMORY(); goto done; } - err = config_from_cmdline(config, &cmdline); - if (_Py_INIT_FAILED(err)) { - goto done; + /* Check config consistency */ + assert(config->isolated >= 0); + assert(config->use_environment >= 0); + assert(config->dev_mode >= 0); + assert(config->install_signal_handlers >= 0); + assert(config->use_hash_seed >= 0); + assert(config->faulthandler >= 0); + assert(config->tracemalloc >= 0); + assert(config->site_import >= 0); + assert(config->bytes_warning >= 0); + assert(config->inspect >= 0); + assert(config->interactive >= 0); + assert(config->optimization_level >= 0); + assert(config->parser_debug >= 0); + assert(config->write_bytecode >= 0); + assert(config->verbose >= 0); + assert(config->quiet >= 0); + assert(config->user_site_directory >= 0); + assert(config->buffered_stdio >= 0); + assert(config->program_name != NULL); + assert(config->program != NULL); + assert(_PyWstrList_CheckConsistency(&config->argv)); + assert(_PyWstrList_CheckConsistency(&config->xoptions)); + assert(_PyWstrList_CheckConsistency(&config->warnoptions)); + assert(_PyWstrList_CheckConsistency(&config->module_search_paths)); + if (config->_install_importlib) { + assert(config->executable != NULL); + assert(config->prefix != NULL); + assert(config->base_prefix != NULL); + assert(config->exec_prefix != NULL); + assert(config->base_exec_prefix != NULL); +#ifdef MS_WINDOWS + assert(config->dll_path != NULL); +#endif } + assert(config->filesystem_encoding != NULL); + assert(config->filesystem_errors != NULL); + assert(config->stdio_encoding != NULL); + assert(config->stdio_errors != NULL); +#ifdef MS_WINDOWS + assert(config->legacy_windows_stdio >= 0); +#endif + assert(config->_check_hash_pycs_mode != NULL); + assert(config->_install_importlib >= 0); + assert(config->_frozen >= 0); + err = _Py_INIT_OK(); done: cmdline_clear(&cmdline); + _PyPreCmdline_Clear(&precmdline); return err; } diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 7fea7c3667..10e141a47d 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -394,7 +394,7 @@ pathconfig_global_init(void) _PyInitError err; _PyCoreConfig config = _PyCoreConfig_INIT; - err = _PyCoreConfig_Read(&config); + err = _PyCoreConfig_Read(&config, NULL); if (_Py_INIT_FAILED(err)) { goto error; } diff --git a/Python/preconfig.c b/Python/preconfig.c index d336352d93..ce63ef0777 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -63,6 +63,7 @@ _Py_SetFileSystemEncoding(const char *encoding, const char *errors) /* --- _PyArgv ---------------------------------------------------- */ +/* Decode bytes_argv using Py_DecodeLocale() */ _PyInitError _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list) { @@ -110,22 +111,6 @@ _PyPreCmdline_Clear(_PyPreCmdline *cmdline) } -int -_PyPreCmdline_Copy(_PyPreCmdline *cmdline, const _PyPreCmdline *cmdline2) -{ - _PyPreCmdline_Clear(cmdline); - if (_PyWstrList_Copy(&cmdline->argv, &cmdline2->argv) < 0) { - return -1; - } - if (_PyWstrList_Copy(&cmdline->xoptions, &cmdline2->xoptions) < 0) { - return -1; - } - cmdline->use_environment = cmdline2->use_environment; - cmdline->isolated = cmdline2->isolated; - return 0; -} - - _PyInitError _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) { @@ -133,7 +118,7 @@ _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) } -void +static void _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) { #define COPY_ATTR(ATTR) \ @@ -141,31 +126,29 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) cmdline->ATTR = config->ATTR; \ } - COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(use_environment); COPY_ATTR(dev_mode); #undef COPY_ATTR } -void +static void _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) { #define COPY_ATTR(ATTR) \ - if (cmdline->ATTR != -1) { \ - config->ATTR = cmdline->ATTR; \ - } + config->ATTR = cmdline->ATTR - COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(use_environment); COPY_ATTR(dev_mode); #undef COPY_ATTR } -void +static void _PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config) { #define COPY_ATTR(ATTR) \ @@ -173,30 +156,126 @@ _PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config) cmdline->ATTR = config->ATTR; \ } - COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(use_environment); COPY_ATTR(dev_mode); #undef COPY_ATTR } -void +int _PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config) { #define COPY_ATTR(ATTR) \ - if (config->ATTR == -1 && cmdline->ATTR != -1) { \ - config->ATTR = cmdline->ATTR; \ + config->ATTR = cmdline->ATTR + + if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) { + return -1; } - COPY_ATTR(use_environment); COPY_ATTR(isolated); + COPY_ATTR(use_environment); COPY_ATTR(dev_mode); + return 0; #undef COPY_ATTR } +/* Parse the command line arguments */ +static _PyInitError +precmdline_parse_cmdline(_PyPreCmdline *cmdline) +{ + _PyWstrList *argv = &cmdline->argv; + + _PyOS_ResetGetOpt(); + /* Don't log parsing errors into stderr here: _PyCoreConfig_Read() + is responsible for that */ + _PyOS_opterr = 0; + do { + int longindex = -1; + int c = _PyOS_GetOpt(argv->length, argv->items, &longindex); + + if (c == EOF || c == 'c' || c == 'm') { + break; + } + + switch (c) { + case 'E': + cmdline->use_environment = 0; + break; + + case 'I': + cmdline->isolated = 1; + break; + + case 'X': + { + if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) { + return _Py_INIT_NO_MEMORY(); + } + break; + } + + default: + /* ignore other argument: + handled by _PyCoreConfig_Read() */ + break; + } + } while (1); + + return _Py_INIT_OK(); +} + + +_PyInitError +_PyPreCmdline_Read(_PyPreCmdline *cmdline, + const _PyPreConfig *preconfig, + const _PyCoreConfig *coreconfig) +{ + if (preconfig) { + _PyPreCmdline_GetPreConfig(cmdline, preconfig); + } + + if (coreconfig) { + _PyPreCmdline_GetCoreConfig(cmdline, coreconfig); + } + + _PyInitError err = precmdline_parse_cmdline(cmdline); + if (_Py_INIT_FAILED(err)) { + return err; + } + + /* isolated, use_environment */ + if (cmdline->isolated < 0) { + cmdline->isolated = 0; + } + if (cmdline->isolated > 0) { + cmdline->use_environment = 0; + } + if (cmdline->use_environment < 0) { + cmdline->use_environment = 0; + } + + /* dev_mode */ + if ((cmdline && _Py_get_xoption(&cmdline->xoptions, L"dev")) + || _Py_GetEnv(cmdline->use_environment, "PYTHONDEVMODE")) + { + cmdline->dev_mode = 1; + } + if (cmdline->dev_mode < 0) { + cmdline->dev_mode = 0; + } + + assert(cmdline->use_environment >= 0); + assert(cmdline->isolated >= 0); + assert(cmdline->dev_mode >= 0); + + return _Py_INIT_OK(); +} + + /* --- _PyPreConfig ----------------------------------------------- */ void @@ -240,17 +319,71 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2) } -void +PyObject* +_PyPreConfig_AsDict(const _PyPreConfig *config) +{ + PyObject *dict; + + dict = PyDict_New(); + if (dict == NULL) { + return NULL; + } + +#define SET_ITEM(KEY, EXPR) \ + do { \ + PyObject *obj = (EXPR); \ + if (obj == NULL) { \ + goto fail; \ + } \ + int res = PyDict_SetItemString(dict, (KEY), obj); \ + Py_DECREF(obj); \ + if (res < 0) { \ + goto fail; \ + } \ + } while (0) +#define SET_ITEM_INT(ATTR) \ + SET_ITEM(#ATTR, PyLong_FromLong(config->ATTR)) +#define FROM_STRING(STR) \ + ((STR != NULL) ? \ + PyUnicode_FromString(STR) \ + : (Py_INCREF(Py_None), Py_None)) +#define SET_ITEM_STR(ATTR) \ + SET_ITEM(#ATTR, FROM_STRING(config->ATTR)) + + SET_ITEM_INT(isolated); + SET_ITEM_INT(use_environment); + SET_ITEM_INT(coerce_c_locale); + SET_ITEM_INT(coerce_c_locale_warn); + SET_ITEM_INT(utf8_mode); +#ifdef MS_WINDOWS + SET_ITEM_INT(legacy_windows_fs_encoding); +#endif + SET_ITEM_INT(dev_mode); + SET_ITEM_STR(allocator); + return dict; + +fail: + Py_DECREF(dict); + return NULL; + +#undef FROM_STRING +#undef SET_ITEM +#undef SET_ITEM_INT +#undef SET_ITEM_STR +} + + +static void _PyPreConfig_GetGlobalConfig(_PyPreConfig *config) { #define COPY_FLAG(ATTR, VALUE) \ - if (config->ATTR == -1) { \ - config->ATTR = VALUE; \ - } + if (config->ATTR == -1) { \ + config->ATTR = VALUE; \ + } #define COPY_NOT_FLAG(ATTR, VALUE) \ - if (config->ATTR == -1) { \ - config->ATTR = !(VALUE); \ - } + if (config->ATTR == -1) { \ + config->ATTR = !(VALUE); \ + } COPY_FLAG(isolated, Py_IsolatedFlag); COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); @@ -264,17 +397,17 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config) } -void +static void _PyPreConfig_SetGlobalConfig(const _PyPreConfig *config) { #define COPY_FLAG(ATTR, VAR) \ - if (config->ATTR != -1) { \ - VAR = config->ATTR; \ - } + if (config->ATTR != -1) { \ + VAR = config->ATTR; \ + } #define COPY_NOT_FLAG(ATTR, VAR) \ - if (config->ATTR != -1) { \ - VAR = !config->ATTR; \ - } + if (config->ATTR != -1) { \ + VAR = !config->ATTR; \ + } COPY_FLAG(isolated, Py_IsolatedFlag); COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); @@ -307,13 +440,6 @@ _Py_GetEnv(int use_environment, const char *name) } -static const char* -_PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name) -{ - return _Py_GetEnv(config->use_environment, name); -} - - int _Py_str_to_int(const char *str, int *result) { @@ -374,6 +500,16 @@ _Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name) static _PyInitError preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) { +#ifdef MS_WINDOWS + if (config->legacy_windows_fs_encoding) { + config->utf8_mode = 0; + } +#endif + + if (config->utf8_mode >= 0) { + return _Py_INIT_OK(); + } + const wchar_t *xopt; if (cmdline) { xopt = _Py_get_xoption(&cmdline->xoptions, L"utf8"); @@ -401,7 +537,7 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) return _Py_INIT_OK(); } - const char *opt = _PyPreConfig_GetEnv(config, "PYTHONUTF8"); + const char *opt = _Py_GetEnv(config->use_environment, "PYTHONUTF8"); if (opt) { if (strcmp(opt, "1") == 0) { config->utf8_mode = 1; @@ -416,92 +552,6 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) return _Py_INIT_OK(); } - return _Py_INIT_OK(); -} - - -static void -preconfig_init_locale(_PyPreConfig *config) -{ - /* The C locale enables the C locale coercion (PEP 538) */ - if (_Py_LegacyLocaleDetected()) { - config->coerce_c_locale = 2; - } - else { - config->coerce_c_locale = 0; - } -} - - -static _PyInitError -preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) -{ - _PyInitError err; - - err = _PyPreCmdline_Read(cmdline); - if (_Py_INIT_FAILED(err)) { - return err; - } - - _PyPreCmdline_SetPreConfig(cmdline, config); - - _PyPreConfig_GetGlobalConfig(config); - - /* isolated and use_environment */ - if (config->isolated > 0) { - config->use_environment = 0; - } - - /* Default values */ - if (config->use_environment < 0) { - config->use_environment = 0; - } - - /* legacy_windows_fs_encoding, utf8_mode, coerce_c_locale */ - if (config->use_environment) { -#ifdef MS_WINDOWS - _Py_get_env_flag(config->use_environment, - &config->legacy_windows_fs_encoding, - "PYTHONLEGACYWINDOWSFSENCODING"); -#endif - - const char *env = _PyPreConfig_GetEnv(config, "PYTHONCOERCECLOCALE"); - if (env) { - if (strcmp(env, "0") == 0) { - if (config->coerce_c_locale < 0) { - config->coerce_c_locale = 0; - } - } - else if (strcmp(env, "warn") == 0) { - config->coerce_c_locale_warn = 1; - } - else { - if (config->coerce_c_locale < 0) { - config->coerce_c_locale = 1; - } - } - } - } - -#ifdef MS_WINDOWS - if (config->legacy_windows_fs_encoding) { - config->utf8_mode = 0; - } -#endif - - if (config->utf8_mode < 0) { - err = preconfig_init_utf8_mode(config, cmdline); - if (_Py_INIT_FAILED(err)) { - return err; - } - } - - /* Test also if coerce_c_locale equals 1: PYTHONCOERCECLOCALE=1 doesn't - imply that the C locale is always coerced. It is only coerced if - if the LC_CTYPE locale is "C". */ - if (config->coerce_c_locale != 0 && config->coerce_c_locale != 2) { - preconfig_init_locale(config); - } #ifndef MS_WINDOWS if (config->utf8_mode < 0) { @@ -516,33 +566,61 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) } #endif - if (config->coerce_c_locale < 0) { - config->coerce_c_locale = 0; - } if (config->utf8_mode < 0) { config->utf8_mode = 0; } - if (config->coerce_c_locale < 0) { - config->coerce_c_locale = 0; + return _Py_INIT_OK(); +} + + +static void +preconfig_init_coerce_c_locale(_PyPreConfig *config) +{ + const char *env = _Py_GetEnv(config->use_environment, "PYTHONCOERCECLOCALE"); + if (env) { + if (strcmp(env, "0") == 0) { + if (config->coerce_c_locale < 0) { + config->coerce_c_locale = 0; + } + } + else if (strcmp(env, "warn") == 0) { + config->coerce_c_locale_warn = 1; + } + else { + if (config->coerce_c_locale < 0) { + config->coerce_c_locale = 1; + } + } } - /* dev_mode */ - if ((cmdline && _Py_get_xoption(&cmdline->xoptions, L"dev")) - || _PyPreConfig_GetEnv(config, "PYTHONDEVMODE")) - { - config->dev_mode = 1; + /* Test if coerce_c_locale equals to -1 or equals to 1: + PYTHONCOERCECLOCALE=1 doesn't imply that the C locale is always coerced. + It is only coerced if if the LC_CTYPE locale is "C". */ + if (config->coerce_c_locale == 0 || config->coerce_c_locale == 2) { + return; + } + + /* The C locale enables the C locale coercion (PEP 538) */ + if (_Py_LegacyLocaleDetected()) { + config->coerce_c_locale = 2; } - if (config->dev_mode < 0) { - config->dev_mode = 0; + else { + config->coerce_c_locale = 0; } - /* allocator */ + assert(config->coerce_c_locale >= 0); +} + + +static _PyInitError +preconfig_init_allocator(_PyPreConfig *config) +{ if (config->allocator == NULL) { /* bpo-34247. The PYTHONMALLOC environment variable has the priority over PYTHONDEV env var and "-X dev" command line option. For example, PYTHONMALLOC=malloc PYTHONDEVMODE=1 sets the memory allocators to "malloc" (and not to "debug"). */ - const char *allocator = _PyPreConfig_GetEnv(config, "PYTHONMALLOC"); + const char *allocator = _Py_GetEnv(config->use_environment, "PYTHONMALLOC"); if (allocator) { config->allocator = _PyMem_RawStrdup(allocator); if (config->allocator == NULL) { @@ -557,130 +635,51 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) return _Py_INIT_NO_MEMORY(); } } - - assert(config->coerce_c_locale >= 0); - assert(config->utf8_mode >= 0); - assert(config->isolated >= 0); - assert(config->use_environment >= 0); - assert(config->dev_mode >= 0); - return _Py_INIT_OK(); } static _PyInitError -get_ctype_locale(char **locale_p) +preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline, + const _PyCoreConfig *coreconfig) { - const char *loc = setlocale(LC_CTYPE, NULL); - if (loc == NULL) { - return _Py_INIT_ERR("failed to LC_CTYPE locale"); - } + _PyInitError err; - char *copy = _PyMem_RawStrdup(loc); - if (copy == NULL) { - return _Py_INIT_NO_MEMORY(); + err = _PyPreCmdline_Read(cmdline, config, coreconfig); + if (_Py_INIT_FAILED(err)) { + return err; } - *locale_p = copy; - return _Py_INIT_OK(); -} + _PyPreCmdline_SetPreConfig(cmdline, config); + /* legacy_windows_fs_encoding, coerce_c_locale, utf8_mode */ +#ifdef MS_WINDOWS + _Py_get_env_flag(config->use_environment, + &config->legacy_windows_fs_encoding, + "PYTHONLEGACYWINDOWSFSENCODING"); +#endif -PyObject* -_PyPreConfig_AsDict(const _PyPreConfig *config) -{ - PyObject *dict; + preconfig_init_coerce_c_locale(config); - dict = PyDict_New(); - if (dict == NULL) { - return NULL; + err = preconfig_init_utf8_mode(config, cmdline); + if (_Py_INIT_FAILED(err)) { + return err; } -#define SET_ITEM(KEY, EXPR) \ - do { \ - PyObject *obj = (EXPR); \ - if (obj == NULL) { \ - goto fail; \ - } \ - int res = PyDict_SetItemString(dict, (KEY), obj); \ - Py_DECREF(obj); \ - if (res < 0) { \ - goto fail; \ - } \ - } while (0) -#define SET_ITEM_INT(ATTR) \ - SET_ITEM(#ATTR, PyLong_FromLong(config->ATTR)) -#define FROM_STRING(STR) \ - ((STR != NULL) ? \ - PyUnicode_FromString(STR) \ - : (Py_INCREF(Py_None), Py_None)) -#define SET_ITEM_STR(ATTR) \ - SET_ITEM(#ATTR, FROM_STRING(config->ATTR)) + /* allocator */ + err = preconfig_init_allocator(config); + if (_Py_INIT_FAILED(err)) { + return err; + } - SET_ITEM_INT(isolated); - SET_ITEM_INT(use_environment); - SET_ITEM_INT(coerce_c_locale); - SET_ITEM_INT(coerce_c_locale_warn); - SET_ITEM_INT(utf8_mode); + assert(config->coerce_c_locale >= 0); #ifdef MS_WINDOWS - SET_ITEM_INT(legacy_windows_fs_encoding); + assert(config->legacy_windows_fs_encoding >= 0); #endif - SET_ITEM_INT(dev_mode); - SET_ITEM_STR(allocator); - return dict; - -fail: - Py_DECREF(dict); - return NULL; - -#undef FROM_STRING -#undef SET_ITEM -#undef SET_ITEM_INT -#undef SET_ITEM_STR -} - - -/* Parse the command line arguments */ -_PyInitError -_PyPreCmdline_Read(_PyPreCmdline *cmdline) -{ - _PyWstrList *argv = &cmdline->argv; - - _PyOS_ResetGetOpt(); - /* Don't log parsing errors into stderr here: _PyCoreConfig_ReadFromArgv() - is responsible for that */ - _PyOS_opterr = 0; - do { - int longindex = -1; - int c = _PyOS_GetOpt(argv->length, argv->items, &longindex); - - if (c == EOF || c == 'c' || c == 'm') { - break; - } - - switch (c) { - case 'E': - cmdline->use_environment = 0; - break; - - case 'I': - cmdline->isolated = 1; - break; - - case 'X': - { - if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) { - return _Py_INIT_NO_MEMORY(); - } - break; - } - - default: - /* ignore other argument: - handled by _PyCoreConfig_ReadFromArgv() */ - break; - } - } while (1); + assert(config->utf8_mode >= 0); + assert(config->isolated >= 0); + assert(config->use_environment >= 0); + assert(config->dev_mode >= 0); return _Py_INIT_OK(); } @@ -688,38 +687,43 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline) /* Read the configuration from: + - command line arguments - environment variables - Py_xxx global configuration variables - - the LC_CTYPE locale - - See _PyPreConfig_ReadFromArgv() to parse also command line arguments. */ + - the LC_CTYPE locale */ _PyInitError _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, const _PyCoreConfig *coreconfig) { _PyInitError err; - _PyPreCmdline cmdline = _PyPreCmdline_INIT; - char *old_loc = NULL; - err = get_ctype_locale(&old_loc); + err = _PyRuntime_Initialize(); if (_Py_INIT_FAILED(err)) { - goto done; + return err; } - /* Set LC_CTYPE to the user preferred locale */ - _Py_SetLocaleFromEnv(LC_CTYPE); - _PyPreConfig_GetGlobalConfig(config); - _PyPreCmdline_GetPreConfig(&cmdline, config); + /* Copy LC_CTYPE locale, since it's modified later */ + const char *loc = setlocale(LC_CTYPE, NULL); + if (loc == NULL) { + return _Py_INIT_ERR("failed to LC_CTYPE locale"); + } + char *init_ctype_locale = _PyMem_RawStrdup(loc); + if (init_ctype_locale == NULL) { + return _Py_INIT_NO_MEMORY(); + } - if (coreconfig) { - _PyPreCmdline_GetCoreConfig(&cmdline, coreconfig); - if (config->dev_mode == -1) { - config->dev_mode = coreconfig->dev_mode; - } + /* Save the config to be able to restore it if encodings change */ + _PyPreConfig save_config = _PyPreConfig_INIT; + if (_PyPreConfig_Copy(&save_config, config) < 0) { + return _Py_INIT_NO_MEMORY(); } + /* Set LC_CTYPE to the user preferred locale */ + _Py_SetLocaleFromEnv(LC_CTYPE); + + _PyPreCmdline cmdline = _PyPreCmdline_INIT; if (args) { err = _PyPreCmdline_SetArgv(&cmdline, args); if (_Py_INIT_FAILED(err)) { @@ -727,61 +731,13 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, } } - err = preconfig_read(config, &cmdline); - -done: - if (old_loc != NULL) { - setlocale(LC_CTYPE, old_loc); - PyMem_RawFree(old_loc); - } - _PyPreCmdline_Clear(&cmdline); - - return err; -} - - -/* Read the configuration from: - - - command line arguments - - environment variables - - Py_xxx global configuration variables - - the LC_CTYPE locale - - See _PyPreConfig_ReadFromArgv() to parse also command line arguments. */ -_PyInitError -_PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) -{ - _PyInitError err; - - err = _PyRuntime_Initialize(); - if (_Py_INIT_FAILED(err)) { - return err; - } - - char *init_ctype_locale = NULL; int init_utf8_mode = Py_UTF8Mode; #ifdef MS_WINDOWS int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag; #endif - _PyPreConfig save_config = _PyPreConfig_INIT; int locale_coerced = 0; int loops = 0; - err = get_ctype_locale(&init_ctype_locale); - if (_Py_INIT_FAILED(err)) { - goto done; - } - - _PyPreConfig_GetGlobalConfig(config); - - if (_PyPreConfig_Copy(&save_config, config) < 0) { - err = _Py_INIT_NO_MEMORY(); - goto done; - } - - /* Set LC_CTYPE to the user preferred locale */ - _Py_SetLocaleFromEnv(LC_CTYPE); - while (1) { int utf8_mode = config->utf8_mode; @@ -800,7 +756,7 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif - err = _PyPreConfig_Read(config, args, NULL); + err = preconfig_read(config, &cmdline, coreconfig); if (_Py_INIT_FAILED(err)) { goto done; } @@ -864,6 +820,7 @@ done: #ifdef MS_WINDOWS Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding; #endif + _PyPreCmdline_Clear(&cmdline); return err; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index b12fa820e9..57b0c3215b 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -482,7 +482,7 @@ _Py_Initialize_ReconfigureCore(PyInterpreterState **interp_p, } *interp_p = interp; - _PyCoreConfig_SetGlobalConfig(core_config); + _PyCoreConfig_Write(core_config); if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) { return _Py_INIT_ERR("failed to copy core config"); @@ -506,7 +506,7 @@ pycore_init_runtime(const _PyCoreConfig *core_config) return _Py_INIT_ERR("main interpreter already initialized"); } - _PyCoreConfig_SetGlobalConfig(core_config); + _PyCoreConfig_Write(core_config); _PyInitError err = _PyRuntime_Initialize(); if (_Py_INIT_FAILED(err)) { @@ -801,7 +801,7 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, return _Py_INIT_ERR("failed to copy core config"); } - _PyInitError err = _PyCoreConfig_Read(config); + _PyInitError err = _PyCoreConfig_Read(config, NULL); if (_Py_INIT_FAILED(err)) { return err; } @@ -833,14 +833,12 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, * safe to call without calling Py_Initialize first) */ _PyInitError -_Py_InitializeCore(PyInterpreterState **interp_p, - const _PyCoreConfig *src_config) +_Py_InitializeCore(const _PyCoreConfig *src_config, + PyInterpreterState **interp_p) { - _PyInitError err; - assert(src_config != NULL); - err = _Py_PreInitializeFromConfig(src_config); + _PyInitError err = _Py_PreInitializeFromConfig(src_config); if (_Py_INIT_FAILED(err)) { return err; } @@ -987,7 +985,7 @@ _Py_InitializeFromConfig(const _PyCoreConfig *config) { PyInterpreterState *interp = NULL; _PyInitError err; - err = _Py_InitializeCore(&interp, config); + err = _Py_InitializeCore(config, &interp); if (_Py_INIT_FAILED(err)) { return err; } -- cgit v1.2.1 From 8b9dbc017a190d13f717e714630d620adb7c7ac2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Mar 2019 01:36:16 +0100 Subject: bpo-36444: Remove _PyMainInterpreterConfig (GH-12571) --- Python/coreconfig.c | 11 ----- Python/pylifecycle.c | 43 +++++++------------ Python/pystate.c | 8 ---- Python/sysmodule.c | 119 ++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 101 insertions(+), 80 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 2f54e79081..944a9e22ca 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -2208,17 +2208,6 @@ _Py_GetConfigsAsDict(void) } Py_CLEAR(dict); - /* main config */ - const _PyMainInterpreterConfig *main_config = _PyInterpreterState_GetMainConfig(interp); - dict = _PyMainInterpreterConfig_AsDict(main_config); - if (dict == NULL) { - goto error; - } - if (PyDict_SetItemString(config, "main_config", dict) < 0) { - goto error; - } - Py_CLEAR(dict); - return config; error: diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 57b0c3215b..ca90e7238b 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -853,14 +853,19 @@ _Py_InitializeCore(const _PyCoreConfig *src_config, configuration. Example of bpo-34008: Py_Main() called after Py_Initialize(). */ static _PyInitError -_Py_ReconfigureMainInterpreter(PyInterpreterState *interp, - const _PyMainInterpreterConfig *config) +_Py_ReconfigureMainInterpreter(PyInterpreterState *interp) { - if (config->argv != NULL) { - int res = PyDict_SetItemString(interp->sysdict, "argv", config->argv); - if (res < 0) { - return _Py_INIT_ERR("fail to set sys.argv"); - } + _PyCoreConfig *core_config = &interp->core_config; + + PyObject *argv = _PyWstrList_AsList(&core_config->argv); + if (argv == NULL) { + return _Py_INIT_NO_MEMORY(); \ + } + + int res = PyDict_SetItemString(interp->sysdict, "argv", argv); + Py_DECREF(argv); + if (res < 0) { + return _Py_INIT_ERR("fail to set sys.argv"); } return _Py_INIT_OK(); } @@ -877,22 +882,17 @@ _Py_ReconfigureMainInterpreter(PyInterpreterState *interp, * non-zero return code. */ _PyInitError -_Py_InitializeMainInterpreter(PyInterpreterState *interp, - const _PyMainInterpreterConfig *config) +_Py_InitializeMainInterpreter(PyInterpreterState *interp) { if (!_PyRuntime.core_initialized) { return _Py_INIT_ERR("runtime core not initialized"); } /* Configure the main interpreter */ - if (_PyMainInterpreterConfig_Copy(&interp->config, config) < 0) { - return _Py_INIT_ERR("failed to copy main interpreter config"); - } - config = &interp->config; _PyCoreConfig *core_config = &interp->core_config; if (_PyRuntime.initialized) { - return _Py_ReconfigureMainInterpreter(interp, config); + return _Py_ReconfigureMainInterpreter(interp); } if (!core_config->_install_importlib) { @@ -929,7 +929,7 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp, return err; } - if (interp->config.install_signal_handlers) { + if (core_config->install_signal_handlers) { err = initsigs(); /* Signal handling stuff, including initintr() */ if (_Py_INIT_FAILED(err)) { return err; @@ -991,12 +991,7 @@ _Py_InitializeFromConfig(const _PyCoreConfig *config) } config = &interp->core_config; - _PyMainInterpreterConfig main_config = _PyMainInterpreterConfig_INIT; - err = _PyMainInterpreterConfig_Read(&main_config, config); - if (!_Py_INIT_FAILED(err)) { - err = _Py_InitializeMainInterpreter(interp, &main_config); - } - _PyMainInterpreterConfig_Clear(&main_config); + err = _Py_InitializeMainInterpreter(interp); if (_Py_INIT_FAILED(err)) { return err; } @@ -1364,24 +1359,18 @@ new_interpreter(PyThreadState **tstate_p) /* Copy the current interpreter config into the new interpreter */ _PyCoreConfig *core_config; - _PyMainInterpreterConfig *config; if (save_tstate != NULL) { core_config = &save_tstate->interp->core_config; - config = &save_tstate->interp->config; } else { /* No current thread state, copy from the main interpreter */ PyInterpreterState *main_interp = PyInterpreterState_Main(); core_config = &main_interp->core_config; - config = &main_interp->config; } if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) { return _Py_INIT_ERR("failed to copy core config"); } core_config = &interp->core_config; - if (_PyMainInterpreterConfig_Copy(&interp->config, config) < 0) { - return _Py_INIT_ERR("failed to copy main interpreter config"); - } err = _PyExc_Init(); if (_Py_INIT_FAILED(err)) { diff --git a/Python/pystate.c b/Python/pystate.c index 6fe3dd1ff3..a2464b6cf5 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -174,7 +174,6 @@ PyInterpreterState_New(void) interp->id_refcount = -1; interp->check_interval = 100; interp->core_config = _PyCoreConfig_INIT; - interp->config = _PyMainInterpreterConfig_INIT; interp->eval_frame = _PyEval_EvalFrameDefault; #ifdef HAVE_DLOPEN #if HAVE_DECL_RTLD_NOW @@ -221,7 +220,6 @@ PyInterpreterState_Clear(PyInterpreterState *interp) PyThreadState_Clear(p); HEAD_UNLOCK(); _PyCoreConfig_Clear(&interp->core_config); - _PyMainInterpreterConfig_Clear(&interp->config); Py_CLEAR(interp->codec_search_path); Py_CLEAR(interp->codec_search_cache); Py_CLEAR(interp->codec_error_registry); @@ -455,12 +453,6 @@ _PyInterpreterState_GetCoreConfig(PyInterpreterState *interp) return &interp->core_config; } -_PyMainInterpreterConfig * -_PyInterpreterState_GetMainConfig(PyInterpreterState *interp) -{ - return &interp->config; -} - PyObject * _PyInterpreterState_GetMainModule(PyInterpreterState *interp) { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 12ec7d5918..1af11c4ab9 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -17,6 +17,7 @@ Data members: #include "Python.h" #include "code.h" #include "frameobject.h" +#include "pycore_coreconfig.h" #include "pycore_pylifecycle.h" #include "pycore_pymem.h" #include "pycore_pathconfig.h" @@ -2530,26 +2531,71 @@ err_occurred: } \ } while (0) + +static int +sys_add_xoption(PyObject *opts, const wchar_t *s) +{ + PyObject *name, *value; + + const wchar_t *name_end = wcschr(s, L'='); + if (!name_end) { + name = PyUnicode_FromWideChar(s, -1); + value = Py_True; + Py_INCREF(value); + } + else { + name = PyUnicode_FromWideChar(s, name_end - s); + value = PyUnicode_FromWideChar(name_end + 1, -1); + } + if (name == NULL || value == NULL) { + goto error; + } + if (PyDict_SetItem(opts, name, value) < 0) { + goto error; + } + Py_DECREF(name); + Py_DECREF(value); + return 0; + +error: + Py_XDECREF(name); + Py_XDECREF(value); + return -1; +} + + +static PyObject* +sys_create_xoptions_dict(const _PyCoreConfig *config) +{ + Py_ssize_t nxoption = config->xoptions.length; + wchar_t * const * xoptions = config->xoptions.items; + PyObject *dict = PyDict_New(); + if (dict == NULL) { + return NULL; + } + + for (Py_ssize_t i=0; i < nxoption; i++) { + const wchar_t *option = xoptions[i]; + if (sys_add_xoption(dict, option) < 0) { + Py_DECREF(dict); + return NULL; + } + } + + return dict; +} + + int _PySys_InitMain(PyInterpreterState *interp) { PyObject *sysdict = interp->sysdict; - const _PyCoreConfig *core_config = &interp->core_config; - const _PyMainInterpreterConfig *config = &interp->config; + const _PyCoreConfig *config = &interp->core_config; int res; - /* _PyMainInterpreterConfig_Read() must set all these variables */ - assert(config->module_search_path != NULL); - assert(config->executable != NULL); - assert(config->prefix != NULL); - assert(config->base_prefix != NULL); - assert(config->exec_prefix != NULL); - assert(config->base_exec_prefix != NULL); - -#define COPY_LIST(KEY, ATTR) \ +#define COPY_LIST(KEY, VALUE) \ do { \ - assert(PyList_Check(ATTR)); \ - PyObject *list = PyList_GetSlice(ATTR, 0, PyList_GET_SIZE(ATTR)); \ + PyObject *list = _PyWstrList_AsList(&(VALUE)); \ if (list == NULL) { \ return -1; \ } \ @@ -2557,36 +2603,41 @@ _PySys_InitMain(PyInterpreterState *interp) Py_DECREF(list); \ } while (0) - COPY_LIST("path", config->module_search_path); +#define SET_SYS_FROM_WSTR(KEY, VALUE) \ + do { \ + PyObject *str = PyUnicode_FromWideChar(VALUE, -1); \ + if (str == NULL) { \ + return -1; \ + } \ + SET_SYS_FROM_STRING_BORROW(KEY, str); \ + Py_DECREF(str); \ + } while (0) - SET_SYS_FROM_STRING_BORROW("executable", config->executable); - SET_SYS_FROM_STRING_BORROW("prefix", config->prefix); - SET_SYS_FROM_STRING_BORROW("base_prefix", config->base_prefix); - SET_SYS_FROM_STRING_BORROW("exec_prefix", config->exec_prefix); - SET_SYS_FROM_STRING_BORROW("base_exec_prefix", config->base_exec_prefix); + COPY_LIST("path", config->module_search_paths); + + SET_SYS_FROM_WSTR("executable", config->executable); + SET_SYS_FROM_WSTR("prefix", config->prefix); + SET_SYS_FROM_WSTR("base_prefix", config->base_prefix); + SET_SYS_FROM_WSTR("exec_prefix", config->exec_prefix); + SET_SYS_FROM_WSTR("base_exec_prefix", config->base_exec_prefix); if (config->pycache_prefix != NULL) { - SET_SYS_FROM_STRING_BORROW("pycache_prefix", config->pycache_prefix); + SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix); } else { PyDict_SetItemString(sysdict, "pycache_prefix", Py_None); } - if (config->argv != NULL) { - SET_SYS_FROM_STRING_BORROW("argv", config->argv); - } - if (config->warnoptions != NULL) { - COPY_LIST("warnoptions", config->warnoptions); - } - if (config->xoptions != NULL) { - PyObject *dict = PyDict_Copy(config->xoptions); - if (dict == NULL) { - return -1; - } - SET_SYS_FROM_STRING_BORROW("_xoptions", dict); - Py_DECREF(dict); + COPY_LIST("argv", config->argv); + COPY_LIST("warnoptions", config->warnoptions); + + PyObject *xoptions = sys_create_xoptions_dict(config); + if (xoptions == NULL) { + return -1; } + SET_SYS_FROM_STRING_BORROW("_xoptions", xoptions); #undef COPY_LIST +#undef SET_SYS_FROM_WSTR /* Set flags to their final values */ SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags()); @@ -2602,7 +2653,7 @@ _PySys_InitMain(PyInterpreterState *interp) } SET_SYS_FROM_STRING_INT_RESULT("dont_write_bytecode", - PyBool_FromLong(!core_config->write_bytecode)); + PyBool_FromLong(!config->write_bytecode)); if (get_warnoptions() == NULL) return -1; -- cgit v1.2.1 From 484f20d2ff95cc2e1bea759852da307bc1d1d944 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Mar 2019 02:04:16 +0100 Subject: bpo-36444: Add _PyCoreConfig._init_main (GH-12572) * Add _PyCoreConfig._init_main: if equals to zero, _Py_InitializeFromConfig() doesn't call _Py_InitializeMainInterpreter(). * Add interp_p parameter to _Py_InitializeFromConfig(). * pymain_init() now calls _Py_InitializeFromConfig(). * Make _Py_InitializeCore() private. --- Python/coreconfig.c | 2 ++ Python/frozenmain.c | 2 +- Python/pylifecycle.c | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 944a9e22ca..ecb22e5667 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -610,6 +610,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) COPY_WSTR_ATTR(run_filename); COPY_ATTR(_check_hash_pycs_mode); COPY_ATTR(_frozen); + COPY_ATTR(_init_main); #undef COPY_ATTR #undef COPY_STR_ATTR @@ -715,6 +716,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config) SET_ITEM_INT(_install_importlib); SET_ITEM_STR(_check_hash_pycs_mode); SET_ITEM_INT(_frozen); + SET_ITEM_INT(_init_main); return dict; diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 6554aa75b0..041b4670ca 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -82,7 +82,7 @@ Py_FrozenMain(int argc, char **argv) if (argc >= 1) Py_SetProgramName(argv_copy[0]); - err = _Py_InitializeFromConfig(&config); + err = _Py_InitializeFromConfig(&config, NULL); /* No need to call _PyCoreConfig_Clear() since we didn't allocate any memory: program_name is a constant string. */ if (_Py_INIT_FAILED(err)) { diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ca90e7238b..f255fd9e13 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -458,7 +458,7 @@ _Py_SetLocaleFromEnv(int category) /* Global initializations. Can be undone by Py_Finalize(). Don't call this twice without an intervening Py_Finalize() call. - Every call to _Py_InitializeCore, Py_Initialize or Py_InitializeEx + Every call to _Py_InitializeFromConfig, Py_Initialize or Py_InitializeEx must have a corresponding call to Py_Finalize. Locking: you must hold the interpreter lock while calling these APIs. @@ -832,7 +832,7 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, * to the Python C API (unless the API is explicitly listed as being * safe to call without calling Py_Initialize first) */ -_PyInitError +static _PyInitError _Py_InitializeCore(const _PyCoreConfig *src_config, PyInterpreterState **interp_p) { @@ -981,7 +981,8 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp) #undef _INIT_DEBUG_PRINT _PyInitError -_Py_InitializeFromConfig(const _PyCoreConfig *config) +_Py_InitializeFromConfig(const _PyCoreConfig *config, + PyInterpreterState **interp_p) { PyInterpreterState *interp = NULL; _PyInitError err; @@ -989,12 +990,18 @@ _Py_InitializeFromConfig(const _PyCoreConfig *config) if (_Py_INIT_FAILED(err)) { return err; } + if (interp_p) { + *interp_p = interp; + } config = &interp->core_config; - err = _Py_InitializeMainInterpreter(interp); - if (_Py_INIT_FAILED(err)) { - return err; + if (config->_init_main) { + err = _Py_InitializeMainInterpreter(interp); + if (_Py_INIT_FAILED(err)) { + return err; + } } + return _Py_INIT_OK(); } @@ -1007,13 +1014,10 @@ Py_InitializeEx(int install_sigs) return; } - _PyInitError err; _PyCoreConfig config = _PyCoreConfig_INIT; config.install_signal_handlers = install_sigs; - err = _Py_InitializeFromConfig(&config); - _PyCoreConfig_Clear(&config); - + _PyInitError err = _Py_InitializeFromConfig(&config, NULL); if (_Py_INIT_FAILED(err)) { _Py_ExitInitError(err); } -- cgit v1.2.1 From 5ac27a50ff2b42216746fedc0522a92c53089bb3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Mar 2019 13:40:14 +0100 Subject: bpo-36444: Rework _Py_InitializeFromConfig() API (GH-12576) --- Python/coreconfig.c | 50 ++++++++++++++++++--------- Python/frozenmain.c | 2 +- Python/preconfig.c | 50 ++++++++++++--------------- Python/pylifecycle.c | 97 ++++++++++++++++++++++++++++++++-------------------- 4 files changed, 116 insertions(+), 83 deletions(-) (limited to 'Python') diff --git a/Python/coreconfig.c b/Python/coreconfig.c index ecb22e5667..13aa227201 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1465,12 +1465,7 @@ static _PyInitError config_read(_PyCoreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; - const _PyPreConfig *preconfig = &_PyRuntime.preconfig; - err = _PyPreCmdline_Read(cmdline, preconfig, config); - if (_Py_INIT_FAILED(err)) { - return err; - } if (_PyPreCmdline_SetCoreConfig(cmdline, config) < 0) { return _Py_INIT_NO_MEMORY(); @@ -2016,6 +2011,35 @@ config_usage(int error, const wchar_t* program) } +static _PyInitError +core_read_precmdline(_PyCoreConfig *config, const _PyArgv *args, + _PyPreCmdline *precmdline) +{ + _PyInitError err; + + if (args) { + err = _PyPreCmdline_SetArgv(precmdline, args); + if (_Py_INIT_FAILED(err)) { + return err; + } + } + + _PyPreConfig preconfig = _PyPreConfig_INIT; + if (_PyPreConfig_Copy(&preconfig, &_PyRuntime.preconfig) < 0) { + err = _Py_INIT_NO_MEMORY(); + goto done; + } + + _PyCoreConfig_GetCoreConfig(&preconfig, config); + + err = _PyPreCmdline_Read(precmdline, &preconfig); + +done: + _PyPreConfig_Clear(&preconfig); + return err; +} + + /* Read the configuration into _PyCoreConfig from: * Command line arguments @@ -2026,7 +2050,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) { _PyInitError err; - err = _Py_PreInitializeFromConfig(config); + err = _Py_PreInitializeFromCoreConfig(config); if (_Py_INIT_FAILED(err)) { return err; } @@ -2034,11 +2058,9 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) _PyCoreConfig_GetGlobalConfig(config); _PyPreCmdline precmdline = _PyPreCmdline_INIT; - if (args) { - err = _PyPreCmdline_SetArgv(&precmdline, args); - if (_Py_INIT_FAILED(err)) { - goto done; - } + err = core_read_precmdline(config, args, &precmdline); + if (_Py_INIT_FAILED(err)) { + goto done; } if (config->program == NULL) { @@ -2048,12 +2070,6 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) } } - const _PyPreConfig *preconfig = &_PyRuntime.preconfig; - err = _PyPreCmdline_Read(&precmdline, preconfig, config); - if (_Py_INIT_FAILED(err)) { - goto done; - } - _PyCmdline cmdline; memset(&cmdline, 0, sizeof(cmdline)); diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 041b4670ca..6554aa75b0 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -82,7 +82,7 @@ Py_FrozenMain(int argc, char **argv) if (argc >= 1) Py_SetProgramName(argv_copy[0]); - err = _Py_InitializeFromConfig(&config, NULL); + err = _Py_InitializeFromConfig(&config); /* No need to call _PyCoreConfig_Clear() since we didn't allocate any memory: program_name is a constant string. */ if (_Py_INIT_FAILED(err)) { diff --git a/Python/preconfig.c b/Python/preconfig.c index ce63ef0777..011ed53a8e 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -148,22 +148,6 @@ _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) } -static void -_PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config) -{ -#define COPY_ATTR(ATTR) \ - if (config->ATTR != -1) { \ - cmdline->ATTR = config->ATTR; \ - } - - COPY_ATTR(isolated); - COPY_ATTR(use_environment); - COPY_ATTR(dev_mode); - -#undef COPY_ATTR -} - - int _PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config) { @@ -231,17 +215,12 @@ precmdline_parse_cmdline(_PyPreCmdline *cmdline) _PyInitError _PyPreCmdline_Read(_PyPreCmdline *cmdline, - const _PyPreConfig *preconfig, - const _PyCoreConfig *coreconfig) + const _PyPreConfig *preconfig) { if (preconfig) { _PyPreCmdline_GetPreConfig(cmdline, preconfig); } - if (coreconfig) { - _PyPreCmdline_GetCoreConfig(cmdline, coreconfig); - } - _PyInitError err = precmdline_parse_cmdline(cmdline); if (_Py_INIT_FAILED(err)) { return err; @@ -373,6 +352,23 @@ fail: } +void +_PyCoreConfig_GetCoreConfig(_PyPreConfig *config, + const _PyCoreConfig *core_config) +{ +#define COPY_ATTR(ATTR) \ + if (core_config->ATTR != -1) { \ + config->ATTR = core_config->ATTR; \ + } + + COPY_ATTR(isolated); + COPY_ATTR(use_environment); + COPY_ATTR(dev_mode); + +#undef COPY_ATTR +} + + static void _PyPreConfig_GetGlobalConfig(_PyPreConfig *config) { @@ -640,12 +636,11 @@ preconfig_init_allocator(_PyPreConfig *config) static _PyInitError -preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline, - const _PyCoreConfig *coreconfig) +preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; - err = _PyPreCmdline_Read(cmdline, config, coreconfig); + err = _PyPreCmdline_Read(cmdline, config); if (_Py_INIT_FAILED(err)) { return err; } @@ -692,8 +687,7 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline, - Py_xxx global configuration variables - the LC_CTYPE locale */ _PyInitError -_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, - const _PyCoreConfig *coreconfig) +_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) { _PyInitError err; @@ -756,7 +750,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif - err = preconfig_read(config, &cmdline, coreconfig); + err = preconfig_read(config, &cmdline); if (_Py_INIT_FAILED(err)) { goto done; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index f255fd9e13..7c6948e6bd 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -718,40 +718,35 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, static _PyInitError -pyinit_preinit(_PyPreConfig *config, - const _PyPreConfig *src_config, - const _PyCoreConfig *coreconfig) +preinit(const _PyPreConfig *src_config, const _PyArgv *args) { _PyInitError err; - _PyPreConfig local_config = _PyPreConfig_INIT; - if (!config) { - config = &local_config; - } err = _PyRuntime_Initialize(); if (_Py_INIT_FAILED(err)) { - goto done; + return err; } if (_PyRuntime.pre_initialized) { /* If it's already configured: ignored the new configuration */ - err = _Py_INIT_OK(); - goto done; + return _Py_INIT_OK(); } + _PyPreConfig config = _PyPreConfig_INIT; + if (src_config) { - if (_PyPreConfig_Copy(config, src_config) < 0) { - err = _Py_INIT_ERR("failed to copy pre config"); + if (_PyPreConfig_Copy(&config, src_config) < 0) { + err = _Py_INIT_NO_MEMORY(); goto done; } } - err = _PyPreConfig_Read(config, NULL, coreconfig); + err = _PyPreConfig_Read(&config, args); if (_Py_INIT_FAILED(err)) { goto done; } - err = _PyPreConfig_Write(config); + err = _PyPreConfig_Write(&config); if (_Py_INIT_FAILED(err)) { goto done; } @@ -760,48 +755,55 @@ pyinit_preinit(_PyPreConfig *config, err = _Py_INIT_OK(); done: - _PyPreConfig_Clear(&local_config); + _PyPreConfig_Clear(&config); return err; } - _PyInitError -_Py_PreInitialize(void) +_Py_PreInitializeFromArgs(const _PyPreConfig *src_config, int argc, char **argv) { - return pyinit_preinit(NULL, NULL, NULL); + _PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv}; + return preinit(src_config, &args); } _PyInitError -_Py_PreInitializeFromPreConfig(const _PyPreConfig *src_config) +_Py_PreInitializeFromWideArgs(const _PyPreConfig *src_config, int argc, wchar_t **argv) { - return pyinit_preinit(NULL, src_config, NULL); + _PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv}; + return preinit(src_config, &args); } _PyInitError -_Py_PreInitializeInPlace(_PyPreConfig *config) +_Py_PreInitialize(const _PyPreConfig *src_config) { - return pyinit_preinit(config, NULL, NULL); + return preinit(src_config, NULL); } _PyInitError -_Py_PreInitializeFromConfig(const _PyCoreConfig *coreconfig) +_Py_PreInitializeFromCoreConfig(const _PyCoreConfig *coreconfig) { - return pyinit_preinit(NULL, NULL, coreconfig); + _PyPreConfig config = _PyPreConfig_INIT; + _PyCoreConfig_GetCoreConfig(&config, coreconfig); + return _Py_PreInitialize(&config); + /* No need to clear config: + _PyCoreConfig_GetCoreConfig() doesn't allocate memory */ } static _PyInitError -pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, +pyinit_coreconfig(_PyCoreConfig *config, + const _PyCoreConfig *src_config, + const _PyArgv *args, PyInterpreterState **interp_p) { if (_PyCoreConfig_Copy(config, src_config) < 0) { return _Py_INIT_ERR("failed to copy core config"); } - _PyInitError err = _PyCoreConfig_Read(config, NULL); + _PyInitError err = _PyCoreConfig_Read(config, args); if (_Py_INIT_FAILED(err)) { return err; } @@ -834,21 +836,23 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, */ static _PyInitError _Py_InitializeCore(const _PyCoreConfig *src_config, + const _PyArgv *args, PyInterpreterState **interp_p) { assert(src_config != NULL); - _PyInitError err = _Py_PreInitializeFromConfig(src_config); + _PyInitError err = _Py_PreInitializeFromCoreConfig(src_config); if (_Py_INIT_FAILED(err)) { return err; } _PyCoreConfig local_config = _PyCoreConfig_INIT; - err = pyinit_coreconfig(&local_config, src_config, interp_p); + err = pyinit_coreconfig(&local_config, src_config, args, interp_p); _PyCoreConfig_Clear(&local_config); return err; } + /* Py_Initialize() has already been called: update the main interpreter configuration. Example of bpo-34008: Py_Main() called after Py_Initialize(). */ @@ -881,7 +885,7 @@ _Py_ReconfigureMainInterpreter(PyInterpreterState *interp) * Other errors should be reported as normal Python exceptions with a * non-zero return code. */ -_PyInitError +static _PyInitError _Py_InitializeMainInterpreter(PyInterpreterState *interp) { if (!_PyRuntime.core_initialized) { @@ -980,19 +984,15 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp) #undef _INIT_DEBUG_PRINT -_PyInitError -_Py_InitializeFromConfig(const _PyCoreConfig *config, - PyInterpreterState **interp_p) +static _PyInitError +init_python(const _PyCoreConfig *config, const _PyArgv *args) { PyInterpreterState *interp = NULL; _PyInitError err; - err = _Py_InitializeCore(config, &interp); + err = _Py_InitializeCore(config, args, &interp); if (_Py_INIT_FAILED(err)) { return err; } - if (interp_p) { - *interp_p = interp; - } config = &interp->core_config; if (config->_init_main) { @@ -1006,6 +1006,29 @@ _Py_InitializeFromConfig(const _PyCoreConfig *config, } +_PyInitError +_Py_InitializeFromArgs(const _PyCoreConfig *config, int argc, char **argv) +{ + _PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv}; + return init_python(config, &args); +} + + +_PyInitError +_Py_InitializeFromWideArgs(const _PyCoreConfig *config, int argc, wchar_t **argv) +{ + _PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv}; + return init_python(config, &args); +} + + +_PyInitError +_Py_InitializeFromConfig(const _PyCoreConfig *config) +{ + return init_python(config, NULL); +} + + void Py_InitializeEx(int install_sigs) { @@ -1017,7 +1040,7 @@ Py_InitializeEx(int install_sigs) _PyCoreConfig config = _PyCoreConfig_INIT; config.install_signal_handlers = install_sigs; - _PyInitError err = _Py_InitializeFromConfig(&config, NULL); + _PyInitError err = _Py_InitializeFromConfig(&config); if (_Py_INIT_FAILED(err)) { _Py_ExitInitError(err); } -- cgit v1.2.1 From 34ef64fe5947bd7e1b075c785fc1125c4e600cd4 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 27 Mar 2019 12:43:47 +0000 Subject: bpo-36447, bpo-36447: Fix refleak in _PySys_InitMain() (GH-12586) Fix refleak in sysmodule.c when calling SET_SYS_FROM_STRING_BORROW. --- Python/sysmodule.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1af11c4ab9..3de94e8468 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2635,6 +2635,7 @@ _PySys_InitMain(PyInterpreterState *interp) return -1; } SET_SYS_FROM_STRING_BORROW("_xoptions", xoptions); + Py_DECREF(xoptions); #undef COPY_LIST #undef SET_SYS_FROM_WSTR -- cgit v1.2.1 From d929f1838a8fba881ff0148b7fc31f6265703e3d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Mar 2019 18:28:46 +0100 Subject: bpo-36443: Disable C locale coercion and UTF-8 Mode by default (GH-12589) bpo-36443, bpo-36202: Since Python 3.7.0, calling Py_DecodeLocale() before Py_Initialize() produces mojibake if the LC_CTYPE locale is coerced and/or if the UTF-8 Mode is enabled by the user configuration. This change fix the issue by disabling LC_CTYPE coercion and UTF-8 Mode by default. They must now be enabled explicitly (opt-in) using the new _Py_PreInitialize() API with _PyPreConfig. When embedding Python, set coerce_c_locale and utf8_mode attributes of _PyPreConfig to -1 to enable automatically these parameters depending on the LC_CTYPE locale, environment variables and command line arguments Alternative: Setting Py_UTF8Mode to 1 always explicitly enables the UTF-8 Mode. Changes: * _PyPreConfig_INIT now sets coerce_c_locale and utf8_mode to 0 by default. * _Py_InitializeFromArgs() and _Py_InitializeFromWideArgs() can now be called with config=NULL. --- Python/preconfig.c | 4 +++- Python/pylifecycle.c | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'Python') diff --git a/Python/preconfig.c b/Python/preconfig.c index 011ed53a8e..7ac645d7f0 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -386,7 +386,9 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config) #ifdef MS_WINDOWS COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag); #endif - COPY_FLAG(utf8_mode, Py_UTF8Mode); + if (Py_UTF8Mode > 0) { + config->utf8_mode = 1; + } #undef COPY_FLAG #undef COPY_NOT_FLAG diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 7c6948e6bd..ad1447256c 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -485,7 +485,7 @@ _Py_Initialize_ReconfigureCore(PyInterpreterState **interp_p, _PyCoreConfig_Write(core_config); if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) { - return _Py_INIT_ERR("failed to copy core config"); + return _Py_INIT_NO_MEMORY(); } core_config = &interp->core_config; @@ -548,7 +548,7 @@ pycore_create_interpreter(const _PyCoreConfig *core_config, *interp_p = interp; if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) { - return _Py_INIT_ERR("failed to copy core config"); + return _Py_INIT_NO_MEMORY(); } core_config = &interp->core_config; @@ -785,6 +785,7 @@ _Py_PreInitialize(const _PyPreConfig *src_config) _PyInitError _Py_PreInitializeFromCoreConfig(const _PyCoreConfig *coreconfig) { + assert(coreconfig != NULL); _PyPreConfig config = _PyPreConfig_INIT; _PyCoreConfig_GetCoreConfig(&config, coreconfig); return _Py_PreInitialize(&config); @@ -799,8 +800,10 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyArgv *args, PyInterpreterState **interp_p) { - if (_PyCoreConfig_Copy(config, src_config) < 0) { - return _Py_INIT_ERR("failed to copy core config"); + if (src_config) { + if (_PyCoreConfig_Copy(config, src_config) < 0) { + return _Py_INIT_NO_MEMORY(); + } } _PyInitError err = _PyCoreConfig_Read(config, args); @@ -839,9 +842,14 @@ _Py_InitializeCore(const _PyCoreConfig *src_config, const _PyArgv *args, PyInterpreterState **interp_p) { - assert(src_config != NULL); + _PyInitError err; - _PyInitError err = _Py_PreInitializeFromCoreConfig(src_config); + if (src_config) { + err = _Py_PreInitializeFromCoreConfig(src_config); + } + else { + err = _Py_PreInitialize(NULL); + } if (_Py_INIT_FAILED(err)) { return err; } @@ -1395,7 +1403,7 @@ new_interpreter(PyThreadState **tstate_p) } if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) { - return _Py_INIT_ERR("failed to copy core config"); + return _Py_INIT_NO_MEMORY(); } core_config = &interp->core_config; -- cgit v1.2.1