Skip to content

Commit ffc408d

Browse files
committed
Remove unused bytecodes.
1 parent 166ccd9 commit ffc408d

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
@@ -1970,7 +1970,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
19701970

19711971
TARGET(BEGIN_FINALLY) {
19721972
/* Push NULL onto the stack for using it in END_FINALLY,
1973-
POP_FINALLY, WITH_CLEANUP_START and WITH_CLEANUP_FINISH.
1973+
POP_FINALLY.
19741974
*/
19751975
PUSH(NULL);
19761976
FAST_DISPATCH();
@@ -3048,116 +3048,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
30483048
DISPATCH();
30493049
}
30503050

3051-
TARGET(WITH_CLEANUP_START) {
3052-
/* At the top of the stack are 1 or 6 values indicating
3053-
how/why we entered the finally clause:
3054-
- TOP = None
3055-
- TOP = the return address (integer)
3056-
- (TOP, SECOND, THIRD) = exc_info()
3057-
(FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER
3058-
Below them is EXIT, the context.__exit__ bound method.
3059-
In the last case, we must call
3060-
EXIT(TOP, SECOND, THIRD)
3061-
otherwise we must call
3062-
EXIT(None, None, None)
3063-
3064-
In the first two cases, we remove EXIT from the
3065-
stack, leaving TOP. In the
3066-
last case, we shift the bottom 3 values of the
3067-
stack down, and replace the empty spot with NULL.
3068-
3069-
In the last case we push TOP on the stack, otherwise we push
3070-
None on the stack. Finally we push the result of the call.
3071-
*/
3072-
PyObject *stack[3];
3073-
PyObject *exit_func;
3074-
PyObject *exc, *val, *tb, *res;
3075-
3076-
val = tb = Py_None;
3077-
exc = TOP();
3078-
if (exc == NULL || PyLong_CheckExact(exc)) {
3079-
STACKADJ(-1);
3080-
exit_func = TOP();
3081-
SET_TOP(exc);
3082-
exc = Py_None;
3083-
}
3084-
else {
3085-
assert(PyExceptionClass_Check(exc));
3086-
PyObject *tp2, *exc2, *tb2;
3087-
PyTryBlock *block;
3088-
val = SECOND();
3089-
tb = THIRD();
3090-
tp2 = FOURTH();
3091-
exc2 = PEEK(5);
3092-
tb2 = PEEK(6);
3093-
exit_func = PEEK(7);
3094-
SET_VALUE(7, tb2);
3095-
SET_VALUE(6, exc2);
3096-
SET_VALUE(5, tp2);
3097-
/* UNWIND_EXCEPT_HANDLER will pop this off. */
3098-
SET_FOURTH(NULL);
3099-
/* We just shifted the stack down, so we have
3100-
to tell the except handler block that the
3101-
values are lower than it expects. */
3102-
assert(f->f_iblock > 0);
3103-
block = &f->f_blockstack[f->f_iblock - 1];
3104-
assert(block->b_type == EXCEPT_HANDLER);
3105-
assert(block->b_level > 0);
3106-
block->b_level--;
3107-
}
3108-
3109-
stack[0] = exc;
3110-
stack[1] = val;
3111-
stack[2] = tb;
3112-
res = _PyObject_FastCall(exit_func, stack, 3);
3113-
Py_DECREF(exit_func);
3114-
if (res == NULL)
3115-
goto error;
3116-
3117-
Py_INCREF(exc); /* Duplicating the exception on the stack */
3118-
PUSH(exc);
3119-
PUSH(res);
3120-
PREDICT(WITH_CLEANUP_FINISH);
3121-
DISPATCH();
3122-
}
3123-
3124-
PREDICTED(WITH_CLEANUP_FINISH);
3125-
TARGET(WITH_CLEANUP_FINISH) {
3126-
/* TOP = the result of calling the context.__exit__ bound method
3127-
SECOND = either None or exception type
3128-
3129-
If SECOND is None below is NULL or the return address,
3130-
otherwise below are 7 values representing an exception.
3131-
*/
3132-
PyObject *res = POP();
3133-
PyObject *exc = POP();
3134-
int err;
3135-
3136-
if (exc != Py_None)
3137-
err = PyObject_IsTrue(res);
3138-
else
3139-
err = 0;
3140-
3141-
Py_DECREF(res);
3142-
Py_DECREF(exc);
3143-
3144-
if (err < 0)
3145-
goto error;
3146-
else if (err > 0) {
3147-
/* There was an exception and a True return.
3148-
* We must manually unwind the EXCEPT_HANDLER block
3149-
* which was created when the exception was caught,
3150-
* otherwise the stack will be in an inconsisten state.
3151-
*/
3152-
PyTryBlock *b = PyFrame_BlockPop(f);
3153-
assert(b->b_type == EXCEPT_HANDLER);
3154-
UNWIND_EXCEPT_HANDLER(b);
3155-
PUSH(NULL);
3156-
}
3157-
PREDICT(END_FINALLY);
3158-
DISPATCH();
3159-
}
3160-
31613051
TARGET(LOAD_METHOD) {
31623052
/* Designed to work in tamdem with CALL_METHOD. */
31633053
PyObject *name = GETITEM(names, oparg);

Python/compile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -941,12 +941,6 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
941941
* Restore the stack position and push 6 values before jumping to
942942
* the handler if an exception be raised. */
943943
return 6;
944-
case WITH_CLEANUP_START:
945-
return 2; /* or 1, depending on TOS */
946-
case WITH_CLEANUP_FINISH:
947-
/* Pop the variable number of values pushed by WITH_CLEANUP_START
948-
* + __exit__ or __aexit__. */
949-
return -3;
950944
case RETURN_VALUE:
951945
return -1;
952946
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)