@@ -4613,39 +4613,50 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
46134613 // Check if the call can be inlined or not
46144614 PyObject * function = PEEK (oparg + 1 );
46154615 if (Py_TYPE (function ) == & PyFunction_Type ) {
4616- PyCodeObject * code = (PyCodeObject * )PyFunction_GET_CODE (function );
4617- PyObject * locals = code -> co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS (function );
4618- if ((code -> co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR )) == 0 ) {
4616+ int code_flags = ((PyCodeObject * )PyFunction_GET_CODE (function ))-> co_flags ;
4617+ PyObject * locals = code_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS (function );
4618+ int is_generator = code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR );
4619+ if (!is_generator ) {
46194620 InterpreterFrame * new_frame = _PyEvalFramePushAndInit (
4620- tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ), locals , stack_pointer - oparg , oparg , NULL , 1 );
4621+ tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ), locals ,
4622+ stack_pointer - oparg ,
4623+ oparg , NULL , 1 );
46214624 if (new_frame == NULL ) {
4622- // When we exit here, we own all variables in the stack (the frame creation has not stolen
4623- // any variable) so we need to clean the whole stack (done in the "error" label).
4625+ // When we exit here, we own all variables in the stack
4626+ // (the frame creation has not stolen any variable) so
4627+ // we need to clean the whole stack (done in the
4628+ // "error" label).
46244629 goto error ;
46254630 }
4631+
46264632 STACK_SHRINK (oparg + 1 );
46274633 assert (tstate -> interp -> eval_frame != NULL );
4628- // The frame has stolen all the arguments from the stack, so there is no need to clean them up.```
4634+ // The frame has stolen all the arguments from the stack,
4635+ // so there is no need to clean them up.
46294636 Py_DECREF (function );
46304637 _PyFrame_SetStackPointer (frame , stack_pointer );
46314638 new_frame -> depth = frame -> depth + 1 ;
46324639 tstate -> frame = frame = new_frame ;
46334640 goto start_frame ;
46344641 }
46354642 else {
4636- /* Callable is a generator or coroutine function: create coroutine or generator. */
4637- res = make_coro (tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ), locals , stack_pointer - oparg , oparg , NULL );
4643+ /* Callable is a generator or coroutine function: create
4644+ * coroutine or generator. */
4645+ res = make_coro (tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ),
4646+ locals , stack_pointer - oparg , oparg , NULL );
46384647 STACK_SHRINK (oparg + 1 );
46394648 for (int i = 0 ; i < oparg + 1 ; i ++ ) {
46404649 Py_DECREF (stack_pointer [i ]);
46414650 }
46424651 }
46434652 }
46444653 else {
4654+ /* Callable is not a Python function */
46454655 PyObject * * sp = stack_pointer ;
46464656 res = call_function (tstate , & sp , oparg , NULL , cframe .use_tracing );
46474657 stack_pointer = sp ;
46484658 }
4659+
46494660 PUSH (res );
46504661 if (res == NULL ) {
46514662 goto error ;
@@ -5678,8 +5689,8 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con,
56785689 // arguments. Notice that we only need to increase the reference count of the
56795690 // *valid* arguments (i.e. the ones that fit into the frame).
56805691 PyCodeObject * co = (PyCodeObject * )con -> fc_code ;
5681- const Py_ssize_t total_args = co -> co_argcount + co -> co_kwonlyargcount ;
5682- for (Py_ssize_t i = 0 ; i < Py_MIN (argcount , total_args ); i ++ ) {
5692+ const size_t total_args = co -> co_argcount + co -> co_kwonlyargcount ;
5693+ for (size_t i = 0 ; i < Py_MIN (argcount , total_args ); i ++ ) {
56835694 Py_XINCREF (frame -> localsplus [i ]);
56845695 }
56855696 }
0 commit comments