From 12a85030bdbbe05fe7112012a06b6e9015cd8bed Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Wed, 31 Aug 2022 09:38:11 +0100 Subject: [PATCH 1/3] gh-96455: update example in exception_handling_notes.txt to the 3.11RC bytecode --- Objects/exception_handling_notes.txt | 48 +++++++++++++++------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/Objects/exception_handling_notes.txt b/Objects/exception_handling_notes.txt index a136358f90c888..5ea50b7169c40b 100644 --- a/Objects/exception_handling_notes.txt +++ b/Objects/exception_handling_notes.txt @@ -43,33 +43,35 @@ SETUP_FINALLY and POP_BLOCK. In 3.11, the SETUP_FINALLY and POP_BLOCK are eliminated, replaced with a table to determine where to jump to when an exception is raised. - 2 0 NOP - - 3 2 LOAD_GLOBAL 0 (g) - 4 LOAD_CONST 1 (0) - 6 CALL_NO_KW 1 - 8 POP_TOP - 10 LOAD_CONST 0 (None) - 12 RETURN_VALUE - >> 14 PUSH_EXC_INFO - - 4 16 POP_TOP - 18 POP_TOP - 20 POP_TOP - - 5 22 POP_EXCEPT - 24 LOAD_CONST 2 ('fail') - 26 RETURN_VALUE - >> 28 POP_EXCEPT_AND_RERAISE + 1 0 RESUME 0 + + 2 2 NOP + + 3 4 LOAD_GLOBAL 1 (NULL + g) + 16 LOAD_CONST 1 (0) + 18 PRECALL 1 + 22 CALL 1 + 32 POP_TOP + 34 LOAD_CONST 0 (None) + 36 RETURN_VALUE + >> 38 PUSH_EXC_INFO + + 4 40 POP_TOP + + 5 42 POP_EXCEPT + 44 LOAD_CONST 2 ('fail') + 46 RETURN_VALUE + >> 48 COPY 3 + 50 POP_EXCEPT + 52 RERAISE 1 ExceptionTable: - 2 to 8 -> 14 [0] - 14 to 20 -> 28 [3] lasti + 4 to 32 -> 38 [0] + 38 to 40 -> 48 [1] lasti -(Note this code is from an early 3.11 alpha, the NOP may well have be removed before release). If an instruction raises an exception then its offset is used to find the target to jump to. -For example, the CALL_NO_KW at offset 6, falls into the range 2 to 8. -So, if g() raises an exception, then control jumps to offset 14. +For example, the CALL at offset 22, falls into the range 4 to 32. +So, if g() raises an exception, then control jumps to offset 38. Unwinding From dbd4ebdda274c926786868e7965f44ba4f2f5c86 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Wed, 31 Aug 2022 17:18:42 +0100 Subject: [PATCH 2/3] update one more place --- Objects/exception_handling_notes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/exception_handling_notes.txt b/Objects/exception_handling_notes.txt index 5ea50b7169c40b..ebd0af3cb81a27 100644 --- a/Objects/exception_handling_notes.txt +++ b/Objects/exception_handling_notes.txt @@ -88,7 +88,7 @@ If there is no relevant entry, the exception bubbles up to the caller. If there is an entry, then: 1. pop values from the stack until it matches the stack depth for the handler, 2. if 'lasti' is true, then push the offset that the exception was raised at. - 3. push the exception to the stack as three values: traceback, value, type, + 3. push the exception to the stack 4. jump to the target offset and resume execution. From abafa1247c04ea66d534af33ec4dcd650978fb74 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 1 Sep 2022 13:14:51 +0100 Subject: [PATCH 3/3] put back note on the code being from 3.11. Fix punctuation. --- Objects/exception_handling_notes.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Objects/exception_handling_notes.txt b/Objects/exception_handling_notes.txt index ebd0af3cb81a27..7de01fdbf5ff48 100644 --- a/Objects/exception_handling_notes.txt +++ b/Objects/exception_handling_notes.txt @@ -68,6 +68,7 @@ ExceptionTable: 4 to 32 -> 38 [0] 38 to 40 -> 48 [1] lasti +(Note this code is from 3.11, later versions may have slightly different bytecode.) If an instruction raises an exception then its offset is used to find the target to jump to. For example, the CALL at offset 22, falls into the range 4 to 32. @@ -86,9 +87,9 @@ This information is stored in the exception table, described below. If there is no relevant entry, the exception bubbles up to the caller. If there is an entry, then: - 1. pop values from the stack until it matches the stack depth for the handler, + 1. pop values from the stack until it matches the stack depth for the handler. 2. if 'lasti' is true, then push the offset that the exception was raised at. - 3. push the exception to the stack + 3. push the exception to the stack. 4. jump to the target offset and resume execution.