Skip to content

GH-104584: Fix ENTER_EXECUTOR #106141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ dummy_func(
ERROR_IF(err, error);
next_instr--;
}
else if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) {
goto handle_eval_breaker;
else if (oparg < 2) {
CHECK_EVAL_BREAKER();
}
}

Expand All @@ -159,6 +159,9 @@ dummy_func(
next_instr--;
}
else {
if (oparg < 2) {
CHECK_EVAL_BREAKER();
}
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _Py_call_instrumentation(
tstate, oparg > 0, frame, next_instr-1);
Expand All @@ -169,9 +172,6 @@ dummy_func(
next_instr = frame->prev_instr;
DISPATCH();
}
if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) {
goto handle_eval_breaker;
}
}
}

Expand Down Expand Up @@ -2143,6 +2143,7 @@ dummy_func(
}

inst(JUMP_BACKWARD, (--)) {
CHECK_EVAL_BREAKER();
_Py_CODEUNIT *here = next_instr - 1;
assert(oparg <= INSTR_OFFSET());
JUMPBY(1-oparg);
Expand All @@ -2160,7 +2161,6 @@ dummy_func(
goto resume_frame;
}
#endif /* ENABLE_SPECIALIZATION */
CHECK_EVAL_BREAKER();
}

pseudo(JUMP) = {
Expand All @@ -2174,6 +2174,9 @@ dummy_func(
};

inst(ENTER_EXECUTOR, (--)) {
CHECK_EVAL_BREAKER();
JUMPBY(1-oparg);
frame->prev_instr = next_instr - 1;
PyCodeObject *code = _PyFrame_GetCode(frame);
_PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[oparg&255];
Py_INCREF(executor);
Expand Down Expand Up @@ -3512,8 +3515,8 @@ dummy_func(
}

inst(INSTRUMENTED_JUMP_BACKWARD, ( -- )) {
INSTRUMENTED_JUMP(next_instr-1, next_instr+1-oparg, PY_MONITORING_EVENT_JUMP);
CHECK_EVAL_BREAKER();
INSTRUMENTED_JUMP(next_instr-1, next_instr+1-oparg, PY_MONITORING_EVENT_JUMP);
}

inst(INSTRUMENTED_POP_JUMP_IF_TRUE, ( -- )) {
Expand Down
2 changes: 0 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int

DISPATCH();

handle_eval_breaker:

/* Do periodic things, like check for signals and async I/0.
* We need to do reasonably frequently, but not too frequently.
* All loops should include a check of the eval breaker.
Expand Down
4 changes: 3 additions & 1 deletion Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@
#define CHECK_EVAL_BREAKER() \
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker)) { \
goto handle_eval_breaker; \
if (_Py_HandlePending(tstate) != 0) { \
goto error; \
} \
}


Expand Down
Loading