10000 gh-106149: Simplify stack depth calculation. Replace asserts by exceptions. by iritkatriel · Pull Request #107255 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-106149: Simplify stack depth calculation. Replace asserts by exceptions. #107255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 26, 2023
Merged
Prev Previous commit
Next Next commit
increment g_maxdepth when adding RETURN_GENERATOR (matches previous s…
…tackdepth)
  • Loading branch information
iritkatriel committed Jul 25, 2023
commit 1cea1e4607a8f814f2febe86caafb616b18d9c6f
10 changes: 4 additions & 6 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7528,17 +7528,15 @@ build_cellfixedoffsets(_PyCompile_CodeUnitMetadata *umd)
}

static int
insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entryblock,
insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, cfg_builder *g,
int *fixed, int nfreevars, int code_flags)
{
basicblock *entryblock = g->g_entryblock;
assert(umd->u_firstlineno > 0);

/* Add the generator prefix instructions. */
if (code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
/* Note that RETURN_GENERATOR + POP_TOP have a net stack effect
* of 0. This is because RETURN_GENERATOR pushes an element
* with _PyFrame_StackPush before switching stacks.
*/
g->g_maxdepth++; /* make space for the value pushed by RETURN_GENERATOR */
cfg_instr make_gen = {
.i_opcode = RETURN_GENERATOR,
.i_oparg = 0,
Expand Down Expand Up @@ -7669,7 +7667,7 @@ prepare_localsplus(_PyCompile_CodeUnitMetadata *umd, cfg_builder *g, int code_fl


// This must be called before fix_cell_offsets().
if (insert_prefix_instructions(umd, g->g_entryblock, cellfixedoffsets, nfreevars, code_flags)) {
if (insert_prefix_instructions(umd, g, cellfixedoffsets, nfreevars, code_flags)) {
PyMem_Free(cellfixedoffsets);
return ERROR;
}
Expand Down
0