Skip to content

Commit 9ffaa2d

Browse files
markshannonMark Shannon
authored andcommitted
Remove unused bytecodes.
1 parent 55c32d2 commit 9ffaa2d

File tree

5 files changed

+4
-123
lines changed

5 files changed

+4
-123
lines changed

Include/opcode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ extern "C" {
5959
#define INPLACE_AND 77
6060
#define INPLACE_XOR 78
6161
#define INPLACE_OR 79
62-
#define WITH_CLEANUP_START 81
63-
#define WITH_CLEANUP_FINISH 82
6462
#define RETURN_VALUE 83
6563
#define IMPORT_STAR 84
6664
#define SETUP_ANNOTATIONS 85

Lib/opcode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def jabs_op(name, op):
118118
def_op('INPLACE_AND', 77)
119119
def_op('INPLACE_XOR', 78)
120120
def_op('INPLACE_OR', 79)
121-
def_op('WITH_CLEANUP_START', 81)
122-
def_op('WITH_CLEANUP_FINISH', 82)
121+
123122
def_op('RETURN_VALUE', 83)
124123
def_op('IMPORT_STAR', 84)
125124
def_op('SETUP_ANNOTATIONS', 85)

Python/ceval.c

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
19161916

19171917
TARGET(BEGIN_FINALLY) {
19181918
/* Push NULL onto the stack for using it in END_FINALLY,
1919-
POP_FINALLY, WITH_CLEANUP_START and WITH_CLEANUP_FINISH.
1919+
POP_FINALLY.
19201920
*/
19211921
PUSH(NULL);
19221922
FAST_DISPATCH();
@@ -2994,116 +2994,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
29942994
DISPATCH();
29952995
}
29962996

2997-
TARGET(WITH_CLEANUP_START) {
2998-
/* At the top of the stack are 1 or 6 values indicating
2999-
how/why we entered the finally clause:
3000-
- TOP = NULL
3001-
- (TOP, SECOND, THIRD) = exc_info()
3002-
(FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER
3003-
Below them is EXIT, the context.__exit__ or context.__aexit__
3004-
bound method.
3005-
In the first case, we must call
3006-
EXIT(None, None, None)
3007-
otherwise we must call
3008-
EXIT(TOP, SECOND, THIRD)
3009-
3010-
In the first case, we remove EXIT from the
3011-
stack, leaving TOP, and push TOP on the stack.
3012-
Otherwise we shift the bottom 3 values of the
3013-
stack down, replace the empty spot with NULL, and push
3014-
None on the stack.
3015-
3016-
Finally we push the result of the call.
3017-
*/
3018-
PyObject *stack[3];
3019-
PyObject *exit_func;
3020-
PyObject *exc, *val, *tb, *res;
3021-
3022-
val = tb = Py_None;
3023-
exc = TOP();
3024-
if (exc == NULL) {
3025-
STACKADJ(-1);
3026-
exit_func = TOP();
3027-
SET_TOP(exc);
3028-
exc = Py_None;
3029-
}
3030-
else {
3031-
assert(PyExceptionClass_Check(exc));
3032-
PyObject *tp2, *exc2, *tb2;
3033-
PyTryBlock *block;
3034-
val = SECOND();
3035-
tb = THIRD();
3036-
tp2 = FOURTH();
3037-
exc2 = PEEK(5);
3038-
tb2 = PEEK(6);
3039-
exit_func = PEEK(7);
3040-
SET_VALUE(7, tb2);
3041-
SET_VALUE(6, exc2);
3042-
SET_VALUE(5, tp2);
3043-
/* UNWIND_EXCEPT_HANDLER will pop this off. */
3044-
SET_FOURTH(NULL);
3045-
/* We just shifted the stack down, so we have
3046-
to tell the except handler block that the
3047-
values are lower than it expects. */
3048-
assert(f->f_iblock > 0);
3049-
block = &f->f_blockstack[f->f_iblock - 1];
3050-
assert(block->b_type == EXCEPT_HANDLER);
3051-
assert(block->b_level > 0);
3052-
block->b_level--;
3053-
}
3054-
3055-
stack[0] = exc;
3056-
stack[1] = val;
3057-
stack[2] = tb;
3058-
res = _PyObject_FastCall(exit_func, stack, 3);
3059-
Py_DECREF(exit_func);
3060-
if (res == NULL)
3061-
goto error;
3062-
3063-
Py_INCREF(exc); /* Duplicating the exception on the stack */
3064-
PUSH(exc);
3065-
PUSH(res);
3066-
PREDICT(WITH_CLEANUP_FINISH);
3067-
DISPATCH();
3068-
}
3069-
3070-
PREDICTED(WITH_CLEANUP_FINISH);
3071-
TARGET(WITH_CLEANUP_FINISH) {
3072-
/* TOP = the result of calling the context.__exit__ bound method
3073-
SECOND = either None or exception type
3074-
3075-
If SECOND is None below is NULL or the return address,
3076-
otherwise below are 7 values representing an exception.
3077-
*/
3078-
PyObject *res = POP();
3079-
PyObject *exc = POP();
3080-
int err;
3081-
3082-
if (exc != Py_None)
3083-
err = PyObject_IsTrue(res);
3084-
else
3085-
err = 0;
3086-
3087-
Py_DECREF(res);
3088-
Py_DECREF(exc);
3089-
3090-
if (err < 0)
3091-
goto error;
3092-
else if (err > 0) {
3093-
/* There was an exception and a True return.
3094-
* We must manually unwind the EXCEPT_HANDLER block
3095-
* which was created when the exception was caught,
3096-
* otherwise the stack will be in an inconsisten state.
3097-
*/
3098-
PyTryBlock *b = PyFrame_BlockPop(f);
3099-
assert(b->b_type == EXCEPT_HANDLER);
3100-
UNWIND_EXCEPT_HANDLER(b);
3101-
PUSH(NULL);
3102-
}
3103-
PREDICT(END_FINALLY);
3104-
DISPATCH();
3105-
}
3106-
31072997
TARGET(LOAD_METHOD) {
31082998
/* Designed to work in tamdem with CALL_METHOD. */
31092999
PyObject *name = GETITEM(names, oparg);

Python/compile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,6 @@ stack_effect(int opcode, int oparg, int jump)
950950
* Restore the stack position and push 6 values before jumping to
951951
* the handler if an exception be raised. */
952952
return jump ? 6 : 1;
953-
case WITH_CLEANUP_START:
954-
return 2; /* or 1, depending on TOS */
955-
case WITH_CLEANUP_FINISH:
956-
/* Pop a variable number of values pushed by WITH_CLEANUP_START
957-
* + __exit__ or __aexit__. */
958-
return -3;
959953
case RETURN_VALUE:
960954
return -1;
961955
case IMPORT_STAR:

Python/opcode_targets.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ static void *opcode_targets[256] = {
8080
&&TARGET_INPLACE_XOR,
8181
&&TARGET_INPLACE_OR,
8282
&&_unknown_opcode,
83-
&&TARGET_WITH_CLEANUP_START,
84-
&&TARGET_WITH_CLEANUP_FINISH,
83+
&&_unknown_opcode,
84+
&&_unknown_opcode,
8585
&&TARGET_RETURN_VALUE,
8686
&&TARGET_IMPORT_STAR,
8787
&&TARGET_SETUP_ANNOTATIONS,

0 commit comments

Comments
 (0)