Skip to content

Commit edde33a

Browse files
Update comments and docs in responce to the review.
1 parent 4d81d0d commit edde33a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Doc/library/dis.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,17 +681,18 @@ iterations of the loop.
681681
used to restore the exception state. An exception handler block is
682682
removed from the block stack.
683683

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`
686686
and :keyword:`return` in the :keyword:`finally` block.
687687

688688
.. versionadded:: 3.7
689689

690690

691691
.. opcode:: BEGIN_FINALLY
692692

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.
695696

696697
.. versionadded:: 3.7
697698

Python/ceval.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,16 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
18991899
}
19001900

19011901
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+
*/
19021912
PyObject *res = NULL;
19031913
if (oparg) {
19041914
res = POP();
@@ -1950,6 +1960,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
19501960
}
19511961

19521962
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+
*/
19531966
PUSH(NULL);
19541967
FAST_DISPATCH();
19551968
}
@@ -1958,7 +1971,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
19581971
TARGET(END_FINALLY) {
19591972
/* At the top of the stack are 1 or 6 values:
19601973
Either:
1961-
- NULL or an integer
1974+
- TOP = NULL or an integer
19621975
or:
19631976
- (TOP, SECOND, THIRD) = exc_info()
19641977
- (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER

Python/compile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,9 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
10361036
return 6;
10371037
case BEGIN_FINALLY:
10381038
/* 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". */
10401042
return 6;
10411043
case CALL_FINALLY:
10421044
return 1;

0 commit comments

Comments
 (0)