Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reorder flow in CALL_FUNCTION to make it a bit clearer.
  • Loading branch information
markshannon committed Sep 23, 2021
commit 9a63ee11a0e2fb74d81446aabbf00e337cc96126
30 changes: 13 additions & 17 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4646,19 +4646,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
if (Py_TYPE(function) == &PyFunction_Type) {
PyCodeObject *code = (PyCodeObject*)PyFunction_GET_CODE(function);
STACK_SHRINK(oparg + 1);
if (code->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
PyObject *locals = code->co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
res = make_coro(
tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer+1, oparg, NULL);
for (int i = 0; i < oparg+1; i++) {
Py_DECREF(stack_pointer[i]);
}
PUSH(res);
if (res == NULL) {
goto error;
}
}
else {
if ((code->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) == 0) {
InterpreterFrame *new_frame = _PyEval_FrameFromPyFunctionAndArgs(tstate, stack_pointer+1, oparg, function);
if (new_frame == NULL) {
// When we exit here, we own all variables in the stack (the frame creation has not stolen
Comment thread
Fidget-Spinner marked this conversation as resolved.
Expand All @@ -4673,15 +4661,23 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
tstate->frame = frame = new_frame;
goto start_frame;
}
else {
/* Callable is a generator or coroutine function: create coroutine or generator. */
PyObject *locals = code->co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
res = make_coro(tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer+1, oparg, NULL);
for (int i = 0; i < oparg+1; i++) {
Py_DECREF(stack_pointer[i]);
}
}
}
else {
PyObject **sp = stack_pointer;
res = call_function(tstate, &sp, oparg, NULL, cframe.use_tracing);
Comment thread
pablogsal marked this conversation as resolved.
stack_pointer = sp;
PUSH(res);
if (res == NULL) {
goto error;
}
}
PUSH(res);
if (res == NULL) {
goto error;
}
CHECK_EVAL_BREAKER();
DISPATCH();
Expand Down