[Python-Dev] An obscene computed goto bytecode hack for "switch" :)
Armin Rigo
arigo at tunes.org
Sat Jun 17 13:18:41 CEST 2006
Hi Phillip,
On Fri, Jun 16, 2006 at 10:01:05PM -0400, Phillip J. Eby wrote:
> One thing I'm curious about, if there are any PyPy folks listening: will
> tricks like this drive PyPy or Psyco insane? :)
Yes, both :-)
The reason is that the details of the stack behavior of END_FINALLY are
messy in CPython. The finally blocks are the only place where the depth
of the stack is not known in advance: depending on how the finally block
is entered, there will be between one and three objects pushed (a single
None, or an int and another object, or an exception type, instance and
traceback). Psyco cheats here and emulates a behavior where there is
always exactly one object instead (which can be a tuple), so if a
END_FINALLY sees values not put there in the "official" way it will just
crash. PyPy works similarily but always expect three values.
(Hum, Psyco could easily be fixed to support your use case... For PyPy
it would be harder without performance hit)
A bientot,
Armin
More information about the Python-Dev
mailing list