Skip to content

Commit 243e441

Browse files
committed
Treat generator functions as normal functions when evaluating and specializing.
1 parent 1b177e3 commit 243e441

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Python/ceval.c

+18-21
Original file line numberDiff line numberDiff line change
@@ -4592,28 +4592,25 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
45924592
// Check if the call can be inlined or not
45934593
if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
45944594
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
4595-
int is_generator = code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR);
4596-
if (!is_generator) {
4597-
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
4598-
STACK_SHRINK(oparg);
4599-
InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
4600-
tstate, (PyFunctionObject *)function, locals,
4601-
stack_pointer, nargs, kwnames
4602-
);
4603-
STACK_SHRINK(postcall_shrink);
4604-
RESET_STACK_ADJUST_FOR_CALLS;
4605-
// The frame has stolen all the arguments from the stack,
4606-
// so there is no need to clean them up.
4607-
Py_XDECREF(kwnames);
4608-
Py_DECREF(function);
4609-
if (new_frame == NULL) {
4610-
goto error;
4611-
}
4612-
_PyFrame_SetStackPointer(frame, stack_pointer);
4613-
new_frame->previous = frame;
4614-
cframe.current_frame = frame = new_frame;
4615-
goto start_frame;
4595+
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
4596+
STACK_SHRINK(oparg);
4597+
InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
4598+
tstate, (PyFunctionObject *)function, locals,
4599+
stack_pointer, nargs, kwnames
4600+
);
4601+
STACK_SHRINK(postcall_shrink);
4602+
RESET_STACK_ADJUST_FOR_CALLS;
4603+
// The frame has stolen all the arguments from the stack,
4604+
// so there is no need to clean them up.
4605+
Py_XDECREF(kwnames);
4606+
Py_DECREF(function);
4607+
if (new_frame == NULL) {
4608+
goto error;
46164609
}
4610+
_PyFrame_SetStackPointer(frame, stack_pointer);
4611+
new_frame->previous = frame;
4612+
cframe.current_frame = frame = new_frame;
4613+
goto start_frame;
46174614
}
46184615
/* Callable is not a normal Python function */
46194616
PyObject *res;

Python/specialize.c

-3
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,6 @@ _Py_IDENTIFIER(__getitem__);
11531153
static int
11541154
function_kind(PyCodeObject *code) {
11551155
int flags = code->co_flags;
1156-
if (flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
1157-
return SPEC_FAIL_GENERATOR;
1158-
}
11591156
if ((flags & (CO_VARKEYWORDS | CO_VARARGS)) || code->co_kwonlyargcount) {
11601157
return SPEC_FAIL_COMPLEX_PARAMETERS;
11611158
}

0 commit comments

Comments
 (0)