RE: [Python-Dev] Is core dump always a bug? Advice requested
On Thursday 13 May 2004 04:43, python-dev-request@python.org wrote:
It's important to read what people who have actually done it have to say about subtleties. For example, your algorithm considered 'return' to be 'a terminal instruction'. But what if it appeared in the 'try' clause of a try/finally construct? In Python's PVM, most *possible* control flow is implicit (virtually any opcode can raise an exception, and from there "magically jump" to the code at an enclosing 'except' or 'finally' clause); and even an unexceptional bare 'return' can magically jump to an enclosing 'finally' block. The Java reference discusses these things, and anyone intending to do something here is still strongly urged to read it.
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'm not saying there are no subtleties as you describe, I'm just trying to quantify some of them and wondering if this is one. -Michel
Michel Pelletier wrote:
But just looking at some code here, is RETURN_VALUE ever inside a SETUP_EXCEPT block?
What about this code:
def foo(): ... try: ... try: ... return 7 ... except: ... pass ... finally: ... print "Hello" ... dis.dis(foo) 2 0 SETUP_FINALLY 22 (to 25)
3 3 SETUP_EXCEPT 8 (to 14) 4 6 LOAD_CONST 1 (7) 9 RETURN_VALUE 10 POP_BLOCK 11 JUMP_FORWARD 7 (to 21) 5 >> 14 POP_TOP 15 POP_TOP 16 POP_TOP 6 17 JUMP_FORWARD 1 (to 21) 20 END_FINALLY >> 21 POP_BLOCK 22 LOAD_CONST 0 (None) 8 >> 25 LOAD_CONST 2 ('Hello') 28 PRINT_ITEM 29 PRINT_NEWLINE 30 END_FINALLY 31 LOAD_CONST 0 (None) 34 RETURN_VALUE
[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>.
On Thursday 13 May 2004 12:04, Michel Pelletier wrote:
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.
Never mind, I proved my self wrong. RETURN_VALUE can often happen inside SETUP_EXCEPT and _FINALLY. Expect the occasionally stupid question (I know, there are no stupid questions....) -Michel
participants (3)
-
"Martin v. Löwis"
-
Michel Pelletier
-
Tim Peters