mirror of
https://github.com/python/cpython.git
synced 2026-05-06 12:49:07 -04:00
gh-148973: fix segfault on mismatch between consts size and oparg in compiler (#148974)
This commit is contained in:
@@ -1081,13 +1081,17 @@ _testinternalcapi.compiler_codegen -> object
|
||||
compile_mode: int = 0
|
||||
|
||||
Apply compiler code generation to an AST.
|
||||
|
||||
Return (instruction_sequence, metadata). metadata maps "argcount",
|
||||
"posonlyargcount", "kwonlyargcount" to ints and "consts" to the list of
|
||||
constants in LOAD_CONST index order (for use with optimize_cfg).
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_testinternalcapi_compiler_codegen_impl(PyObject *module, PyObject *ast,
|
||||
PyObject *filename, int optimize,
|
||||
int compile_mode)
|
||||
/*[clinic end generated code: output=40a68f6e13951cc8 input=a0e00784f1517cd7]*/
|
||||
/*[clinic end generated code: output=40a68f6e13951cc8 input=e0c65e5c80efe30e]*/
|
||||
{
|
||||
PyCompilerFlags *flags = NULL;
|
||||
return _PyCompile_CodeGen(ast, filename, flags, optimize, compile_mode);
|
||||
@@ -1103,12 +1107,15 @@ _testinternalcapi.optimize_cfg -> object
|
||||
nlocals: int
|
||||
|
||||
Apply compiler optimizations to an instruction list.
|
||||
|
||||
consts must be a list aligned with LOAD_CONST opargs (the "consts" entry
|
||||
from the metadata dict returned by compiler_codegen for the same unit).
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions,
|
||||
PyObject *consts, int nlocals)
|
||||
/*[clinic end generated code: output=57c53c3a3dfd1df0 input=6a96d1926d58d7e5]*/
|
||||
/*[clinic end generated code: output=57c53c3a3dfd1df0 input=905c3d935e063b27]*/
|
||||
{
|
||||
return _PyCompile_OptimizeCfg(instructions, consts, nlocals);
|
||||
}
|
||||
|
||||
Generated
+10
-3
@@ -92,7 +92,11 @@ PyDoc_STRVAR(_testinternalcapi_compiler_codegen__doc__,
|
||||
"compiler_codegen($module, /, ast, filename, optimize, compile_mode=0)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Apply compiler code generation to an AST.");
|
||||
"Apply compiler code generation to an AST.\n"
|
||||
"\n"
|
||||
"Return (instruction_sequence, metadata). metadata maps \"argcount\",\n"
|
||||
"\"posonlyargcount\", \"kwonlyargcount\" to ints and \"consts\" to the list of\n"
|
||||
"constants in LOAD_CONST index order (for use with optimize_cfg).");
|
||||
|
||||
#define _TESTINTERNALCAPI_COMPILER_CODEGEN_METHODDEF \
|
||||
{"compiler_codegen", _PyCFunction_CAST(_testinternalcapi_compiler_codegen), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_compiler_codegen__doc__},
|
||||
@@ -169,7 +173,10 @@ PyDoc_STRVAR(_testinternalcapi_optimize_cfg__doc__,
|
||||
"optimize_cfg($module, /, instructions, consts, nlocals)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Apply compiler optimizations to an instruction list.");
|
||||
"Apply compiler optimizations to an instruction list.\n"
|
||||
"\n"
|
||||
"consts must be a list aligned with LOAD_CONST opargs (the \"consts\" entry\n"
|
||||
"from the metadata dict returned by compiler_codegen for the same unit).");
|
||||
|
||||
#define _TESTINTERNALCAPI_OPTIMIZE_CFG_METHODDEF \
|
||||
{"optimize_cfg", _PyCFunction_CAST(_testinternalcapi_optimize_cfg), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_optimize_cfg__doc__},
|
||||
@@ -392,4 +399,4 @@ get_next_dict_keys_version(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return get_next_dict_keys_version_impl(module);
|
||||
}
|
||||
/*[clinic end generated code: output=fbd8b7e0cae8bac7 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=ecb5d7ac85b153fa input=a9049054013a1b77]*/
|
||||
|
||||
Reference in New Issue
Block a user