@@ -2240,13 +2240,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2240
2240
DEOPT_IF (getitem -> func_version != cache -> func_version , BINARY_SUBSCR );
2241
2241
PyCodeObject * code = (PyCodeObject * )getitem -> func_code ;
2242
2242
assert (code -> co_argcount == 2 );
2243
+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), BINARY_SUBSCR );
2243
2244
STAT_INC (BINARY_SUBSCR , hit );
2244
-
2245
2245
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 );
2250
2247
CALL_STAT_INC (inlined_py_calls );
2251
2248
STACK_SHRINK (2 );
2252
2249
new_frame -> localsplus [0 ] = container ;
@@ -3664,13 +3661,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3664
3661
DEOPT_IF (f -> func_version != func_version , LOAD_ATTR );
3665
3662
PyCodeObject * code = (PyCodeObject * )f -> func_code ;
3666
3663
assert (code -> co_argcount == 1 );
3664
+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), LOAD_ATTR );
3667
3665
STAT_INC (LOAD_ATTR , hit );
3668
-
3669
3666
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 );
3674
3668
SET_TOP (NULL );
3675
3669
int push_null = !(oparg & 1 );
3676
3670
STACK_SHRINK (push_null );
@@ -4724,7 +4718,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4724
4718
// Check if the call can be inlined or not
4725
4719
if (Py_TYPE (function ) == & PyFunction_Type && tstate -> interp -> eval_frame == NULL ) {
4726
4720
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 ) );
4728
4722
STACK_SHRINK (total_args );
4729
4723
_PyInterpreterFrame * new_frame = _PyEvalFramePushAndInit (
4730
4724
tstate , (PyFunctionObject * )function , locals ,
@@ -4810,11 +4804,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4810
4804
DEOPT_IF (func -> func_version != read_u32 (cache -> func_version ), CALL );
4811
4805
PyCodeObject * code = (PyCodeObject * )func -> func_code ;
4812
4806
DEOPT_IF (code -> co_argcount != argcount , CALL );
4807
+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), CALL );
4813
4808
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 );
4818
4810
CALL_STAT_INC (inlined_py_calls );
4819
4811
STACK_SHRINK (argcount );
4820
4812
for (int i = 0 ; i < argcount ; i ++ ) {
@@ -4846,11 +4838,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4846
4838
DEOPT_IF (argcount > code -> co_argcount , CALL );
4847
4839
int minargs = cache -> min_args ;
4848
4840
DEOPT_IF (argcount < minargs , CALL );
4841
+ DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), CALL );
4849
4842
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 );
4854
4844
CALL_STAT_INC (inlined_py_calls );
4855
4845
STACK_SHRINK (argcount );
4856
4846
for (int i = 0 ; i < argcount ; i ++ ) {
@@ -6298,20 +6288,19 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
6298
6288
return -1 ;
6299
6289
}
6300
6290
6301
- /* Consumes references to func and all the args */
6291
+ /* Consumes references to func, locals and all the args */
6302
6292
static _PyInterpreterFrame *
6303
6293
_PyEvalFramePushAndInit (PyThreadState * tstate , PyFunctionObject * func ,
6304
6294
PyObject * locals , PyObject * const * args ,
6305
6295
size_t argcount , PyObject * kwnames )
6306
6296
{
6307
6297
PyCodeObject * code = (PyCodeObject * )func -> func_code ;
6308
- size_t size = code -> co_nlocalsplus + code -> co_stacksize + FRAME_SPECIALS_SIZE ;
6309
6298
CALL_STAT_INC (frames_pushed );
6310
- _PyInterpreterFrame * frame = _PyThreadState_BumpFramePointer (tstate , size );
6299
+ _PyInterpreterFrame * frame = _PyThreadState_PushFrame (tstate , code -> co_framesize );
6311
6300
if (frame == NULL ) {
6312
6301
goto fail ;
6313
6302
}
6314
- _PyFrame_InitializeSpecials (frame , func , locals , code -> co_nlocalsplus );
6303
+ _PyFrame_InitializeSpecials (frame , func , locals , code );
6315
6304
PyObject * * localsarray = & frame -> localsplus [0 ];
6316
6305
for (int i = 0 ; i < code -> co_nlocalsplus ; i ++ ) {
6317
6306
localsarray [i ] = NULL ;
@@ -6355,8 +6344,9 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func,
6355
6344
PyObject * kwnames )
6356
6345
{
6357
6346
/* _PyEvalFramePushAndInit consumes the references
6358
- * to func and all its arguments */
6347
+ * to func, locals and all its arguments */
6359
6348
Py_INCREF (func );
6349
+ Py_XINCREF (locals );
6360
6350
for (size_t i = 0 ; i < argcount ; i ++ ) {
6361
6351
Py_INCREF (args [i ]);
6362
6352
}
0 commit comments