[Python-Dev] Is core dump always a bug? Advice requested

Tim Peters tim.one at comcast.net
Thu May 13 15:32:30 EDT 2004


[Michel Pelletier]
> But just looking at some code here, is RETURN_VALUE ever inside a
> SETUP_EXCEPT block?  The end of the SETUP_EXCEPT block apears to
> ABSOLUTE_JUMP past all the exception handlers to finally, and then to
> the RETURN_VALUE, which doesn't seem to fall under the protection of a
> try/except.

I don't think I can understand what you're saying without a concrete
example.  Here's one:

"""
def f():
    try:
        return 42
    finally:
        print 'yup'

from dis import dis
dis(f)
"""

That displays:

"""
  2           0 SETUP_FINALLY            8 (to 11)

  3           3 LOAD_CONST               1 (42)
              6 RETURN_VALUE
              7 POP_BLOCK
              8 LOAD_CONST               0 (None)

  4     >>   11 LOAD_CONST               2 ('yup')

  5          14 PRINT_ITEM
             15 PRINT_NEWLINE
             16 END_FINALLY
             17 LOAD_CONST               0 (None)
             20 RETURN_VALUE
"""

The RETURN_VALUE at 6 doesn't return right away, although that's not obvious
from the byte code.  The code at 11, 14, 15, 16 executes first, and that
can't be guessed from staring at 6 in isolation.  I think the code at 7, 8,
17 and 20 is actually unreachable -- and that's so not obvious I had to say
"I think" <wink>.




More information about the Python-Dev mailing list