@@ -4613,39 +4613,50 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
4613
4613
// Check if the call can be inlined or not
4614
4614
PyObject * function = PEEK (oparg + 1 );
4615
4615
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 ) {
4619
4620
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 );
4621
4624
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).
4624
4629
goto error ;
4625
4630
}
4631
+
4626
4632
STACK_SHRINK (oparg + 1 );
4627
4633
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.
4629
4636
Py_DECREF (function );
4630
4637
_PyFrame_SetStackPointer (frame , stack_pointer );
4631
4638
new_frame -> depth = frame -> depth + 1 ;
4632
4639
tstate -> frame = frame = new_frame ;
4633
4640
goto start_frame ;
4634
4641
}
4635
4642
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 );
4638
4647
STACK_SHRINK (oparg + 1 );
4639
4648
for (int i = 0 ; i < oparg + 1 ; i ++ ) {
4640
4649
Py_DECREF (stack_pointer [i ]);
4641
4650
}
4642
4651
}
4643
4652
}
4644
4653
else {
4654
+ /* Callable is not a Python function */
4645
4655
PyObject * * sp = stack_pointer ;
4646
4656
res = call_function (tstate , & sp , oparg , NULL , cframe .use_tracing );
4647
4657
stack_pointer = sp ;
4648
4658
}
4659
+
4649
4660
PUSH (res );
4650
4661
if (res == NULL ) {
4651
4662
goto error ;
@@ -5678,8 +5689,8 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con,
5678
5689
// arguments. Notice that we only need to increase the reference count of the
5679
5690
// *valid* arguments (i.e. the ones that fit into the frame).
5680
5691
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 ++ ) {
5683
5694
Py_XINCREF (frame -> localsplus [i ]);
5684
5695
}
5685
5696
}
0 commit comments