@@ -2240,13 +2240,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
22402240 DEOPT_IF (getitem -> func_version != cache -> func_version , BINARY_SUBSCR );
22412241 PyCodeObject * code = (PyCodeObject * )getitem -> func_code ;
22422242 assert (code -> co_argcount == 2 );
2243+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), BINARY_SUBSCR );
22432244 STAT_INC (BINARY_SUBSCR , hit );
2244-
22452245 Py_INCREF (getitem );
2246- _PyInterpreterFrame * new_frame = _PyFrame_Push (tstate , getitem );
2247- if (new_frame == NULL ) {
2248- goto error ;
2249- }
2246+ _PyInterpreterFrame * new_frame = _PyFrame_PushUnchecked (tstate , getitem );
22502247 CALL_STAT_INC (inlined_py_calls );
22512248 STACK_SHRINK (2 );
22522249 new_frame -> localsplus [0 ] = container ;
@@ -3664,13 +3661,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
36643661 DEOPT_IF (f -> func_version != func_version , LOAD_ATTR );
36653662 PyCodeObject * code = (PyCodeObject * )f -> func_code ;
36663663 assert (code -> co_argcount == 1 );
3664+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), LOAD_ATTR );
36673665 STAT_INC (LOAD_ATTR , hit );
3668-
36693666 Py_INCREF (fget );
3670- _PyInterpreterFrame * new_frame = _PyFrame_Push (tstate , f );
3671- if (new_frame == NULL ) {
3672- goto error ;
3673- }
3667+ _PyInterpreterFrame * new_frame = _PyFrame_PushUnchecked (tstate , f );
36743668 SET_TOP (NULL );
36753669 int push_null = !(oparg & 1 );
36763670 STACK_SHRINK (push_null );
@@ -4724,7 +4718,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
47244718 // Check if the call can be inlined or not
47254719 if (Py_TYPE (function ) == & PyFunction_Type && tstate -> interp -> eval_frame == NULL ) {
47264720 int code_flags = ((PyCodeObject * )PyFunction_GET_CODE (function ))-> co_flags ;
4727- PyObject * locals = code_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS (function );
4721+ PyObject * locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef ( PyFunction_GET_GLOBALS (function ) );
47284722 STACK_SHRINK (total_args );
47294723 _PyInterpreterFrame * new_frame = _PyEvalFramePushAndInit (
47304724 tstate , (PyFunctionObject * )function , locals ,
@@ -4810,11 +4804,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
48104804 DEOPT_IF (func -> func_version != read_u32 (cache -> func_version ), CALL );
48114805 PyCodeObject * code = (PyCodeObject * )func -> func_code ;
48124806 DEOPT_IF (code -> co_argcount != argcount , CALL );
4807+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), CALL );
48134808 STAT_INC (CALL , hit );
4814- _PyInterpreterFrame * new_frame = _PyFrame_Push (tstate , func );
4815- if (new_frame == NULL ) {
4816- goto error ;
4817- }
4809+ _PyInterpreterFrame * new_frame = _PyFrame_PushUnchecked (tstate , func );
48184810 CALL_STAT_INC (inlined_py_calls );
48194811 STACK_SHRINK (argcount );
48204812 for (int i = 0 ; i < argcount ; i ++ ) {
@@ -4846,11 +4838,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
48464838 DEOPT_IF (argcount > code -> co_argcount , CALL );
48474839 int minargs = cache -> min_args ;
48484840 DEOPT_IF (argcount < minargs , CALL );
4841+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), CALL );
48494842 STAT_INC (CALL , hit );
4850- _PyInterpreterFrame * new_frame = _PyFrame_Push (tstate , func );
4851- if (new_frame == NULL ) {
4852- goto error ;
4853- }
4843+ _PyInterpreterFrame * new_frame = _PyFrame_PushUnchecked (tstate , func );
48544844 CALL_STAT_INC (inlined_py_calls );
48554845 STACK_SHRINK (argcount );
48564846 for (int i = 0 ; i < argcount ; i ++ ) {
@@ -6298,20 +6288,19 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
62986288 return -1 ;
62996289}
63006290
6301- /* Consumes references to func and all the args */
6291+ /* Consumes references to func, locals and all the args */
63026292static _PyInterpreterFrame *
63036293_PyEvalFramePushAndInit (PyThreadState * tstate , PyFunctionObject * func ,
63046294 PyObject * locals , PyObject * const * args ,
63056295 size_t argcount , PyObject * kwnames )
63066296{
63076297 PyCodeObject * code = (PyCodeObject * )func -> func_code ;
6308- size_t size = code -> co_nlocalsplus + code -> co_stacksize + FRAME_SPECIALS_SIZE ;
63096298 CALL_STAT_INC (frames_pushed );
6310- _PyInterpreterFrame * frame = _PyThreadState_BumpFramePointer (tstate , size );
6299+ _PyInterpreterFrame * frame = _PyThreadState_PushFrame (tstate , code -> co_framesize );
63116300 if (frame == NULL ) {
63126301 goto fail ;
63136302 }
6314- _PyFrame_InitializeSpecials (frame , func , locals , code -> co_nlocalsplus );
6303+ _PyFrame_InitializeSpecials (frame , func , locals , code );
63156304 PyObject * * localsarray = & frame -> localsplus [0 ];
63166305 for (int i = 0 ; i < code -> co_nlocalsplus ; i ++ ) {
63176306 localsarray [i ] = NULL ;
@@ -6355,8 +6344,9 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func,
63556344 PyObject * kwnames )
63566345{
63576346 /* _PyEvalFramePushAndInit consumes the references
6358- * to func and all its arguments */
6347+ * to func, locals and all its arguments */
63596348 Py_INCREF (func );
6349+ Py_XINCREF (locals );
63606350 for (size_t i = 0 ; i < argcount ; i ++ ) {
63616351 Py_INCREF (args [i ]);
63626352 }
0 commit comments