File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -681,17 +681,18 @@ iterations of the loop.
681
681
used to restore the exception state. An exception handler block is
682
682
removed from the block stack.
683
683
684
- It is similar to :opcode: `END_FINALLY `, but neither change the bytecode
685
- counter nor raises an exception. Used for implementing :keyword: `break `
684
+ It is similar to :opcode: `END_FINALLY `, but doesn't change the bytecode
685
+ counter nor raise an exception. Used for implementing :keyword: `break `
686
686
and :keyword: `return ` in the :keyword: `finally ` block.
687
687
688
688
.. versionadded :: 3.7
689
689
690
690
691
691
.. opcode :: BEGIN_FINALLY
692
692
693
- Pushes ``NULL `` onto the stack for using it in :opcode: `END_FINALLY `.
694
- Starts the :keyword: `finally ` block.
693
+ Pushes ``NULL `` onto the stack for using it in :opcode: `END_FINALLY `,
694
+ :opcode: `POP_FINALLY `, :opcode: `WITH_CLEANUP_START ` and
695
+ :opcode: `WITH_CLEANUP_FINISH `. Starts the :keyword: `finally ` block.
695
696
696
697
.. versionadded :: 3.7
697
698
Original file line number Diff line number Diff line change @@ -1899,6 +1899,16 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
1899
1899
}
1900
1900
1901
1901
TARGET (POP_FINALLY ) {
1902
+ /* If oparg is 0 at the top of the stack are 1 or 6 values:
1903
+ Either:
1904
+ - TOP = NULL or an integer
1905
+ or:
1906
+ - (TOP, SECOND, THIRD) = exc_info()
1907
+ - (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER
1908
+
1909
+ If oparg is 1 the value for 'return' was additionally pushed
1910
+ at the top of the stack.
1911
+ */
1902
1912
PyObject * res = NULL ;
1903
1913
if (oparg ) {
1904
1914
res = POP ();
@@ -1950,6 +1960,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
1950
1960
}
1951
1961
1952
1962
TARGET (BEGIN_FINALLY ) {
1963
+ /* Push NULL onto the stack for using it in END_FINALLY,
1964
+ POP_FINALLY, WITH_CLEANUP_START and WITH_CLEANUP_FINISH.
1965
+ */
1953
1966
PUSH (NULL );
1954
1967
FAST_DISPATCH ();
1955
1968
}
@@ -1958,7 +1971,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
1958
1971
TARGET (END_FINALLY ) {
1959
1972
/* At the top of the stack are 1 or 6 values:
1960
1973
Either:
1961
- - NULL or an integer
1974
+ - TOP = NULL or an integer
1962
1975
or:
1963
1976
- (TOP, SECOND, THIRD) = exc_info()
1964
1977
- (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER
Original file line number Diff line number Diff line change @@ -1036,7 +1036,9 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
1036
1036
return 6 ;
1037
1037
case BEGIN_FINALLY :
1038
1038
/* Actually pushes 1 value, but count 6 for balancing with
1039
- * END_FINALLY and POP_FINALLY. */
1039
+ * END_FINALLY and POP_FINALLY.
1040
+ * This is the main reason of using this opcode instead of
1041
+ * "LOAD_CONST None". */
1040
1042
return 6 ;
1041
1043
case CALL_FINALLY :
1042
1044
return 1 ;
You can’t perform that action at this time.
0 commit comments