Repost: A bizarre and insidious traceback/local-vars bug

Kenneth Manheimer (klm@nist.gov)
Tue, 26 Jul 1994 19:25:52 GMT

I've already forwarded this one to guido, who has confirmed it.
(Notice the pathetic plea for acknowledgement at the bottom:( )

-=- -=- -=-

I'm running python 1.0.3 on a Sun Sparc (690MP), under SunOS 4.1.3.

The configure command i used, as reported in my config.status (but
with the line wrapped by hand), is:

./configure --exec_prefix=/depot/sundry/plat --prefix=/depot/sundry \
--with-readline=/depot/gnu/plat/lib/ --with-stdwin

The following function, weird(), should print out the dictionary of
its' local variables twice. However, it only prints out the correct
thing after a call to vars(), even though the value the call is
ignored.

import sys # ... for sys.exc_traceback
def weird():
x = "i'm here!" # a local var
whatever = 'whatever' # another to be used as an exception
try: raise whatever # provoke a traceback
except whatever: # and catch it
at = sys.exc_traceback.tb_frame
where = at.f_code
print at.f_locals # here i get: {}
vars()
print at.f_locals # but here i get: {'whatever': ...}

Then:

>>> weird()
{}
{'whatever': 'whatever', 'where': <code object weird at a47b0, file \
"<stdin>", line 1>, 'at': <frame object at a4948>, 'x': "i'm here!"}
>>>

I suspect that this exposes a problem involving the ceval.c function
fast_2_locals(), and suppose that there is some sort of optimization
that is backfiring a bit, but i wouldn't even presume to guess exactly
what was intended.

I have another, perhaps related problem if i try to refer to the local
vars using a single consolidated reference -

a = sys.exc_traceback.tb_frame.f_code.f_locals

provokes an attribute error, while the piecemeal assignments at least
don't raise an exception. How very odd!

Two questions:

1 Does anyone else see this same problem? (I wonder the same thing
about the composite default-values problem i posted about yesterday.)
2 Anyone have a quick fix?
(3) Have my recent posts been getting through? I've seen no responses,
and though i realize that this is vacation time, etc, i'm getting a
bit paranoid about being snubbed!

Thanks!

Ken
ken.manheimer@nist.gov, 301 975-3539