Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 56530:16db2a932248
Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
| author | Neil Schemenauer <nascheme@enme.ucalgary.ca> |
|---|---|
| date | Wed, 14 Oct 2009 19:14:38 +0000 |
| parents | 79718ee03986 |
| children | 3bc6fb3c0ccd |
line wrap: on
line diff
--- a/Python/compile.c Wed Oct 14 18:46:15 2009 +0000 +++ b/Python/compile.c Wed Oct 14 19:14:38 2009 +0000 @@ -772,7 +772,7 @@ case UNPACK_EX: return (oparg&0xFF) + (oparg>>8); case FOR_ITER: - return 1; + return 1; /* or -1, at end of iterator */ case STORE_ATTR: return -2; @@ -799,7 +799,7 @@ case COMPARE_OP: return -1; case IMPORT_NAME: - return 0; + return -1; case IMPORT_FROM: return 1; @@ -3546,7 +3546,7 @@ static int stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth) { - int i; + int i, target_depth; struct instr *instr; if (b->b_seen || b->b_startdepth >= depth) return maxdepth; @@ -3559,8 +3559,17 @@ maxdepth = depth; assert(depth >= 0); /* invalid code or bug in stackdepth() */ if (instr->i_jrel || instr->i_jabs) { + 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; + } maxdepth = stackdepth_walk(c, instr->i_target, - depth, maxdepth); + target_depth, maxdepth); if (instr->i_opcode == JUMP_ABSOLUTE || instr->i_opcode == JUMP_FORWARD) { goto out; /* remaining code is dead */
