@@ -1523,24 +1523,6 @@ trace_function_entry(PyThreadState *tstate, InterpreterFrame *frame)
1523
1523
return 0 ;
1524
1524
}
1525
1525
1526
- /* Create a frame structure from a python function stealing ownership from an array of arguments.
1527
- * In case of error, it returns NULL and the caller still owns the references to all arguments */
1528
- static InterpreterFrame *
1529
- _PyEval_FrameFromPyFunctionAndArgs (PyThreadState * tstate , PyObject * const * args , int nargs , PyObject * function ) {
1530
- assert (PyFunction_Check (function ));
1531
- size_t nargsf = nargs | PY_VECTORCALL_ARGUMENTS_OFFSET ;
1532
- assert (args != NULL || PyVectorcall_NARGS (nargsf ) == 0 );
1533
- assert (PyVectorcall_Function (function ) == _PyFunction_Vectorcall );
1534
- PyFrameConstructor * con = PyFunction_AS_FRAME_CONSTRUCTOR (function );
1535
- Py_ssize_t vector_nargs = PyVectorcall_NARGS (nargsf );
1536
- assert (vector_nargs >= 0 );
1537
- assert (vector_nargs == 0 || args != NULL );
1538
- PyCodeObject * code = (PyCodeObject * )con -> fc_code ;
1539
- PyObject * locals = (code -> co_flags & CO_OPTIMIZED ) ? NULL : con -> fc_globals ;
1540
- assert (!(code -> co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR )));
1541
- return _PyEvalFramePushAndInit (tstate , con , locals , args , vector_nargs , NULL , 1 );
1542
- }
1543
-
1544
1526
static PyObject *
1545
1527
make_coro (PyThreadState * tstate , PyFrameConstructor * con ,
1546
1528
PyObject * locals ,
@@ -4645,14 +4627,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
4645
4627
PyObject * function = PEEK (oparg + 1 );
4646
4628
if (Py_TYPE (function ) == & PyFunction_Type ) {
4647
4629
PyCodeObject * code = (PyCodeObject * )PyFunction_GET_CODE (function );
4648
- STACK_SHRINK ( oparg + 1 );
4630
+ PyObject * locals = code -> co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS ( function );
4649
4631
if ((code -> co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR )) == 0 ) {
4650
- InterpreterFrame * new_frame = _PyEval_FrameFromPyFunctionAndArgs (tstate , stack_pointer + 1 , oparg , function );
4632
+ InterpreterFrame * new_frame = _PyEvalFramePushAndInit (
4633
+ tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ), locals , stack_pointer - oparg , oparg , NULL , 1 );
4651
4634
if (new_frame == NULL ) {
4652
4635
// When we exit here, we own all variables in the stack (the frame creation has not stolen
4653
4636
// any variable) so we need to clean the whole stack (done in the "error" label).
4654
4637
goto error ;
4655
4638
}
4639
+ STACK_SHRINK (oparg + 1 );
4656
4640
assert (tstate -> interp -> eval_frame != NULL );
4657
4641
// The frame has stolen all the arguments from the stack, so there is no need to clean them up.```
4658
4642
Py_DECREF (function );
@@ -4663,9 +4647,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
4663
4647
}
4664
4648
else {
4665
4649
/* 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 ++ ) {
4650
+ res = make_coro ( tstate , PyFunction_AS_FRAME_CONSTRUCTOR ( function ), locals , stack_pointer - oparg , oparg , NULL );
4651
+ STACK_SHRINK ( oparg + 1 );
4652
+ for (int i = 0 ; i < oparg + 1 ; i ++ ) {
4669
4653
Py_DECREF (stack_pointer [i ]);
4670
4654
}
4671
4655
}
0 commit comments