https://github.com/python/cpython/commit/dc8df6e84024b79aa96e85a64f354bf8e827bcba
commit: dc8df6e84024b79aa96e85a64f354bf8e827bcba
branch: main
author: Mark Shannon <[email protected]>
committer: markshannon <[email protected]>
date: 2024-01-03T11:01:13Z
summary:

GH-113595: Don't enter invalid executor (GH-113596)

files:
M Python/bytecodes.c
M Python/generated_cases.c.h

diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 29e1dab184ef4e..2eeeac53e1dd7e 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2364,17 +2364,27 @@ dummy_func(
 
             PyCodeObject *code = _PyFrame_GetCode(frame);
             _PyExecutorObject *executor = (_PyExecutorObject 
*)code->co_executors->executors[oparg&255];
-            Py_INCREF(executor);
-            if (executor->execute == _PyUOpExecute) {
-                current_executor = (_PyUOpExecutorObject *)executor;
-                GOTO_TIER_TWO();
+            if (executor->vm_data.valid) {
+                Py_INCREF(executor);
+                if (executor->execute == _PyUOpExecute) {
+                    current_executor = (_PyUOpExecutorObject *)executor;
+                    GOTO_TIER_TWO();
+                }
+                next_instr = executor->execute(executor, frame, stack_pointer);
+                frame = tstate->current_frame;
+                if (next_instr == NULL) {
+                    goto resume_with_error;
+                }
+                stack_pointer = _PyFrame_GetStackPointer(frame);
             }
-            next_instr = executor->execute(executor, frame, stack_pointer);
-            frame = tstate->current_frame;
-            if (next_instr == NULL) {
-                goto resume_with_error;
+            else {
+                opcode = this_instr->op.code = executor->vm_data.opcode;
+                this_instr->op.arg = executor->vm_data.oparg;
+                oparg = (oparg & (~255)) | executor->vm_data.oparg;
+                code->co_executors->executors[oparg&255] = NULL;
+                Py_DECREF(executor);
+                DISPATCH_GOTO();
             }
-            stack_pointer = _PyFrame_GetStackPointer(frame);
         }
 
         replaced op(_POP_JUMP_IF_FALSE, (cond -- )) {
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index ce31967b7912d7..99fd169ca4fec3 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -2371,24 +2371,34 @@
         }
 
         TARGET(ENTER_EXECUTOR) {
-            frame->instr_ptr = next_instr;
+            _Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;
             next_instr += 1;
             INSTRUCTION_STATS(ENTER_EXECUTOR);
             TIER_ONE_ONLY
             CHECK_EVAL_BREAKER();
             PyCodeObject *code = _PyFrame_GetCode(frame);
             _PyExecutorObject *executor = (_PyExecutorObject 
*)code->co_executors->executors[oparg&255];
-            Py_INCREF(executor);
-            if (executor->execute == _PyUOpExecute) {
-                current_executor = (_PyUOpExecutorObject *)executor;
-                GOTO_TIER_TWO();
+            if (executor->vm_data.valid) {
+                Py_INCREF(executor);
+                if (executor->execute == _PyUOpExecute) {
+                    current_executor = (_PyUOpExecutorObject *)executor;
+                    GOTO_TIER_TWO();
+                }
+                next_instr = executor->execute(executor, frame, stack_pointer);
+                frame = tstate->current_frame;
+                if (next_instr == NULL) {
+                    goto resume_with_error;
+                }
+                stack_pointer = _PyFrame_GetStackPointer(frame);
             }
-            next_instr = executor->execute(executor, frame, stack_pointer);
-            frame = tstate->current_frame;
-            if (next_instr == NULL) {
-                goto resume_with_error;
+            else {
+                opcode = this_instr->op.code = executor->vm_data.opcode;
+                this_instr->op.arg = executor->vm_data.oparg;
+                oparg = (oparg & (~255)) | executor->vm_data.oparg;
+                code->co_executors->executors[oparg&255] = NULL;
+                Py_DECREF(executor);
+                DISPATCH_GOTO();
             }
-            stack_pointer = _PyFrame_GetStackPointer(frame);
             DISPATCH();
         }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to