Skip to content

Commit 9a63ee1

Browse files
committed
Reorder flow in CALL_FUNCTION to make it a bit clearer.
1 parent a2c0994 commit 9a63ee1

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

Python/ceval.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,19 +4646,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
46464646
if (Py_TYPE(function) == &PyFunction_Type) {
46474647
PyCodeObject *code = (PyCodeObject*)PyFunction_GET_CODE(function);
46484648
STACK_SHRINK(oparg + 1);
4649-
if (code->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
4650-
PyObject *locals = code->co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
4651-
res = make_coro(
4652-
tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer+1, oparg, NULL);
4653-
for (int i = 0; i < oparg+1; i++) {
4654-
Py_DECREF(stack_pointer[i]);
4655-
}
4656-
PUSH(res);
4657-
if (res == NULL) {
4658-
goto error;
4659-
}
4660-
}
4661-
else {
4649+
if ((code->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) == 0) {
46624650
InterpreterFrame *new_frame = _PyEval_FrameFromPyFunctionAndArgs(tstate, stack_pointer+1, oparg, function);
46634651
if (new_frame == NULL) {
46644652
// When we exit here, we own all variables in the stack (the frame creation has not stolen
@@ -4673,15 +4661,23 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
46734661
tstate->frame = frame = new_frame;
46744662
goto start_frame;
46754663
}
4664+
else {
4665+
/* Callable is a generator or coroutine function: create coroutine or generator. */
4666+
PyObject *locals = code->co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
4667+
res = make_coro(tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer+1, oparg, NULL);
4668+
for (int i = 0; i < oparg+1; i++) {
4669+
Py_DECREF(stack_pointer[i]);
4670+
}
4671+
}
46764672
}
46774673
else {
46784674
PyObject **sp = stack_pointer;
46794675
res = call_function(tstate, &sp, oparg, NULL, cframe.use_tracing);
46804676
stack_pointer = sp;
4681-
PUSH(res);
4682-
if (res == NULL) {
4683-
goto error;
4684-
}
4677+
}
4678+
PUSH(res);
4679+
if (res == NULL) {
4680+
goto error;
46854681
}
46864682
CHECK_EVAL_BREAKER();
46874683
DISPATCH();

0 commit comments

Comments
 (0)