This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tighter co_stacksize computation in stackdepth_walk
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: nascheme Nosy List: ctl, nascheme
Priority: normal Keywords: patch

Created on 2007-07-14 20:38 by ctl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch-tighter-stack-depth ctl, 2007-07-14 20:38
Messages (2)
msg52876 - (view) Author: Christopher Tur Lesniewski-Laas (ctl) Date: 2007-07-14 20:38
The existing code in stackdepth_walk gives conservative, but not very tight, bounds for stack depth.  Some of this is simply bugs: for example,
  import a,b,c,d,e,f,...,z
will leak a stack slot for each import, and
  a[:],b[:],c[:],...,z[:]
leaks a stack slot for each SLICE+0 opcode.

Some of it is because stackdepth_walk assumes that the stack effect of jumps is the same at the target.  In particular, a sequence of for-loops will leak 2 stack slots for each for-loop.

The attached patch fixes both of these problems.  It corrects the stack effect for several opcodes that were simply incorrect (perhaps from an older version?).  It also changes stackdepth_walk to treat FOR_ITER, SETUP_EXCEPT, and SETUP_FINALLY specially when following their targets.

Note: this patch also introduces a dependency from stackdepth_walk to the compiler, because it assumes that END_FINALLY is always preceded by the target of a SETUP_EXCEPT or SETUP_FINALLY.
msg94013 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2009-10-14 19:15
Committed to the Python 2.x and 3.x trunks.
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45198
2009-10-14 19:15:10naschemesetstatus: open -> closed
resolution: accepted
messages: + msg94013
2009-02-07 00:25:37naschemesetassignee: nascheme
nosy: + nascheme
2007-07-14 20:38:17ctlcreate