Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve stack size calculation for SETUP_{EXCEPT,FINALLY}
  • Loading branch information
pitrou committed Jul 23, 2017
commit b699364d229c64956d323ae408546ebdc866e979
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
TARGET(WITH_EXCEPT_FINISH) {
PyObject *res = POP();
PyObject *exc = POP();
PyObject *val, *tb;
int err;

if (exc != Py_None)
Expand Down Expand Up @@ -3191,6 +3190,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
DISPATCH();
}
else {
PyObject *val, *tb;
assert(TOP() == exc);
STACKADJ(-1);
val = POP();
Expand Down
15 changes: 7 additions & 8 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5158,8 +5158,11 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
{
int i, target_depth, effect;
struct instr *instr;
if (b->b_seen || b->b_startdepth >= depth)

if (b->b_seen || b->b_startdepth >= depth) {
return maxdepth;
}
/* Guard against infinite recursion */
b->b_seen = 1;
b->b_startdepth = depth;
for (i = 0; i < b->b_iused; i++) {
Expand All @@ -5175,19 +5178,15 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
maxdepth = depth;
assert(depth >= 0); /* invalid code or bug in stackdepth() */
if (instr->i_jrel || instr->i_jabs) {
/* Recursively inspect jump target */
target_depth = depth;
if (instr->i_opcode == FOR_ITER) {
target_depth = depth-2;
}
else if (instr->i_opcode == SETUP_FINALLY ||
instr->i_opcode == SETUP_EXCEPT) {
target_depth = depth+3;
if (target_depth > maxdepth)
maxdepth = target_depth;
}
else if (instr->i_opcode == JUMP_IF_TRUE_OR_POP ||
instr->i_opcode == JUMP_IF_FALSE_OR_POP)
instr->i_opcode == JUMP_IF_FALSE_OR_POP) {
depth = depth - 1;
}
maxdepth = stackdepth_walk(c, instr->i_target,
target_depth, maxdepth);
if (instr->i_opcode == JUMP_ABSOLUTE ||
Expand Down