diff options
Diffstat (limited to 'contrib/tools/python3/Python/compile.c')
| -rw-r--r-- | contrib/tools/python3/Python/compile.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/contrib/tools/python3/Python/compile.c b/contrib/tools/python3/Python/compile.c index 8f8b6773440..4ab1280e91d 100644 --- a/contrib/tools/python3/Python/compile.c +++ b/contrib/tools/python3/Python/compile.c @@ -7844,6 +7844,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, { PyObject *res = NULL; PyObject *metadata = NULL; + PyObject *consts_list = NULL; if (!PyAST_Check(ast)) { PyErr_SetString(PyExc_TypeError, "expected an AST"); @@ -7889,7 +7890,6 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, SET_MATADATA_ITEM("name", umd->u_name); SET_MATADATA_ITEM("qualname", umd->u_qualname); - SET_MATADATA_ITEM("consts", umd->u_consts); SET_MATADATA_ITEM("names", umd->u_names); SET_MATADATA_ITEM("varnames", umd->u_varnames); SET_MATADATA_ITEM("cellvars", umd->u_cellvars); @@ -7915,12 +7915,21 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, } if (_PyInstructionSequence_ApplyLabelMap(INSTR_SEQUENCE(c)) < 0) { - return NULL; + goto finally; + } + /* After add_return_at_end: const indices match final instruction stream. */ + consts_list = consts_dict_keys_inorder(umd->u_consts); + if (consts_list == NULL) { + goto finally; + } + if (PyDict_SetItemString(metadata, "consts", consts_list) < 0) { + goto finally; } /* Allocate a copy of the instruction sequence on the heap */ res = PyTuple_Pack(2, INSTR_SEQUENCE(c), metadata); finally: + Py_XDECREF(consts_list); Py_XDECREF(metadata); compiler_exit_scope(c); compiler_free(c); @@ -7935,6 +7944,10 @@ _PyCompile_OptimizeCfg(PyObject *seq, PyObject *consts, int nlocals) PyErr_SetString(PyExc_ValueError, "expected an instruction sequence"); return NULL; } + if (!PyList_Check(consts)) { + PyErr_SetString(PyExc_TypeError, "consts must be a list"); + return NULL; + } PyObject *const_cache = PyDict_New(); if (const_cache == NULL) { return NULL; |
