@@ -1549,6 +1549,7 @@ eval_frame_handle_pending(PyThreadState *tstate)
1549
1549
1550
1550
#define GLOBALS () specials[FRAME_SPECIALS_GLOBALS_OFFSET]
1551
1551
#define BUILTINS () specials[FRAME_SPECIALS_BUILTINS_OFFSET]
1552
+ #define LOCALS () specials[FRAME_SPECIALS_LOCALS_OFFSET]
1552
1553
1553
1554
PyObject * _Py_HOT_FUNCTION
1554
1555
_PyEval_EvalFrameDefault (PyThreadState * tstate , PyFrameObject * f , int throwflag )
@@ -2759,7 +2760,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
2759
2760
case TARGET (STORE_NAME ): {
2760
2761
PyObject * name = GETITEM (names , oparg );
2761
2762
PyObject * v = POP ();
2762
- PyObject * ns = f -> f_locals ;
2763
+ PyObject * ns = LOCALS () ;
2763
2764
int err ;
2764
2765
if (ns == NULL ) {
2765
2766
_PyErr_Format (tstate , PyExc_SystemError ,
@@ -2779,7 +2780,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
2779
2780
2780
2781
case TARGET (DELETE_NAME ): {
2781
2782
PyObject * name = GETITEM (names , oparg );
2782
- PyObject * ns = f -> f_locals ;
2783
+ PyObject * ns = LOCALS () ;
2783
2784
int err ;
2784
2785
if (ns == NULL ) {
2785
2786
_PyErr_Format (tstate , PyExc_SystemError ,
@@ -2894,7 +2895,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
2894
2895
2895
2896
case TARGET (LOAD_NAME ): {
2896
2897
PyObject * name = GETITEM (names , oparg );
2897
- PyObject * locals = f -> f_locals ;
2898
+ PyObject * locals = LOCALS () ;
2898
2899
PyObject * v ;
2899
2900
if (locals == NULL ) {
2900
2901
_PyErr_Format (tstate , PyExc_SystemError ,
@@ -3076,7 +3077,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
3076
3077
}
3077
3078
3078
3079
case TARGET (LOAD_CLASSDEREF ): {
3079
- PyObject * name , * value , * locals = f -> f_locals ;
3080
+ PyObject * name , * value , * locals = LOCALS () ;
3080
3081
Py_ssize_t idx ;
3081
3082
assert (locals );
3082
3083
assert (oparg >= PyTuple_GET_SIZE (co -> co_cellvars ));
@@ -3269,14 +3270,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
3269
3270
_Py_IDENTIFIER (__annotations__ );
3270
3271
int err ;
3271
3272
PyObject * ann_dict ;
3272
- if (f -> f_locals == NULL ) {
3273
+ if (LOCALS () == NULL ) {
3273
3274
_PyErr_Format (tstate , PyExc_SystemError ,
3274
3275
"no locals found when setting up annotations" );
3275
3276
goto error ;
3276
3277
}
3277
3278
/* check if __annotations__ in locals()... */
3278
- if (PyDict_CheckExact (f -> f_locals )) {
3279
- ann_dict = _PyDict_GetItemIdWithError (f -> f_locals ,
3279
+ if (PyDict_CheckExact (LOCALS () )) {
3280
+ ann_dict = _PyDict_GetItemIdWithError (LOCALS () ,
3280
3281
& PyId___annotations__ );
3281
3282
if (ann_dict == NULL ) {
3282
3283
if (_PyErr_Occurred (tstate )) {
@@ -3287,7 +3288,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
3287
3288
if (ann_dict == NULL ) {
3288
3289
goto error ;
3289
3290
}
3290
- err = _PyDict_SetItemId (f -> f_locals ,
3291
+ err = _PyDict_SetItemId (LOCALS () ,
3291
3292
& PyId___annotations__ , ann_dict );
3292
3293
Py_DECREF (ann_dict );
3293
3294
if (err != 0 ) {
@@ -3301,7 +3302,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
3301
3302
if (ann_str == NULL ) {
3302
3303
goto error ;
3303
3304
}
3304
- ann_dict = PyObject_GetItem (f -> f_locals , ann_str );
3305
+ ann_dict = PyObject_GetItem (LOCALS () , ann_str );
3305
3306
if (ann_dict == NULL ) {
3306
3307
if (!_PyErr_ExceptionMatches (tstate , PyExc_KeyError )) {
3307
3308
goto error ;
@@ -3311,7 +3312,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
3311
3312
if (ann_dict == NULL ) {
3312
3313
goto error ;
3313
3314
}
3314
- err = PyObject_SetItem (f -> f_locals , ann_str , ann_dict );
3315
+ err = PyObject_SetItem (LOCALS () , ann_str , ann_dict );
3315
3316
Py_DECREF (ann_dict );
3316
3317
if (err != 0 ) {
3317
3318
goto error ;
@@ -3710,7 +3711,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
3710
3711
goto error ;
3711
3712
}
3712
3713
3713
- locals = f -> f_locals ;
3714
+ locals = LOCALS () ;
3714
3715
if (locals == NULL ) {
3715
3716
_PyErr_SetString (tstate , PyExc_SystemError ,
3716
3717
"no locals found during 'import *'" );
@@ -5837,8 +5838,10 @@ PyEval_GetLocals(void)
5837
5838
return NULL ;
5838
5839
}
5839
5840
5840
- assert (current_frame -> f_locals != NULL );
5841
- return current_frame -> f_locals ;
5841
+ PyObject * locals = current_frame -> f_valuestack [
5842
+ FRAME_SPECIALS_LOCALS_OFFSET - FRAME_SPECIALS_SIZE ];
5843
+ assert (locals != NULL );
5844
+ return locals ;
5842
5845
}
5843
5846
5844
5847
PyObject *
@@ -6107,6 +6110,8 @@ import_name(PyThreadState *tstate, PyFrameObject *f,
6107
6110
}
6108
6111
return NULL ;
6109
6112
}
6113
+ PyObject * locals = f -> f_valuestack [
6114
+ FRAME_SPECIALS_LOCALS_OFFSET - FRAME_SPECIALS_SIZE ];
6110
6115
/* Fast path for not overloaded __import__. */
6111
6116
if (import_func == tstate -> interp -> import_func ) {
6112
6117
int ilevel = _PyLong_AsInt (level );
@@ -6116,7 +6121,7 @@ import_name(PyThreadState *tstate, PyFrameObject *f,
6116
6121
res = PyImport_ImportModuleLevelObject (
6117
6122
name ,
6118
6123
_PyFrame_GetGlobals (f ),
6119
- f -> f_locals == NULL ? Py_None : f -> f_locals ,
6124
+ locals == NULL ? Py_None :locals ,
6120
6125
fromlist ,
6121
6126
ilevel );
6122
6127
return res ;
@@ -6126,7 +6131,7 @@ import_name(PyThreadState *tstate, PyFrameObject *f,
6126
6131
6127
6132
stack [0 ] = name ;
6128
6133
stack [1 ] = _PyFrame_GetGlobals (f );
6129
- stack [2 ] = f -> f_locals == NULL ? Py_None : f -> f_locals ;
6134
+ stack [2 ] = locals == NULL ? Py_None : locals ;
6130
6135
stack [3 ] = fromlist ;
6131
6136
stack [4 ] = level ;
6132
6137
res = _PyObject_FastCall (import_func , stack , 5 );
@@ -6471,7 +6476,8 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w,
6471
6476
{
6472
6477
PyObject * names = f -> f_code -> co_names ;
6473
6478
PyObject * name = GETITEM (names , oparg );
6474
- PyObject * locals = f -> f_locals ;
6479
+ PyObject * locals = f -> f_valuestack [
6480
+ FRAME_SPECIALS_LOCALS_OFFSET - FRAME_SPECIALS_SIZE ];
6475
6481
if (locals && PyDict_CheckExact (locals )) {
6476
6482
PyObject * w = PyDict_GetItemWithError (locals , name );
6477
6483
if ((w == v && PyDict_DelItem (locals , name ) != 0 ) ||
0 commit comments