@@ -206,6 +206,29 @@ framelocalsproxy_getitem(PyObject *self, PyObject *key)
206
206
return NULL ;
207
207
}
208
208
209
+ static int
210
+ add_overwritten_fast_local (PyFrameObject * frame , PyObject * obj )
211
+ {
212
+ Py_ssize_t new_size = 1 ;
213
+ if (frame -> f_overwritten_fast_locals != NULL ) {
214
+ new_size = PyTuple_Size (frame -> f_overwritten_fast_locals );
215
+ if (new_size == -1 ) {
216
+ return -1 ;
217
+ }
218
+ }
219
+ PyObject * new_tuple = PyTuple_New (new_size );
220
+ if (new_tuple == NULL ) {
221
+ return -1 ;
222
+ }
223
+ for (Py_ssize_t i = 0 ; i < new_size - 1 ; i ++ ) {
224
+ PyObject * o = PyTuple_GET_ITEM (frame -> f_overwritten_fast_locals , i );
225
+ PyTuple_SET_ITEM (new_tuple , i , Py_NewRef (o ));
226
+ }
227
+ PyTuple_SET_ITEM (new_tuple , new_size - 1 , Py_NewRef (obj ));
228
+ Py_XSETREF (frame -> f_overwritten_fast_locals , new_tuple );
229
+ return 0 ;
230
+ }
231
+
209
232
static int
210
233
framelocalsproxy_setitem (PyObject * self , PyObject * key , PyObject * value )
211
234
{
@@ -246,13 +269,7 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
246
269
} else if (value != PyStackRef_AsPyObjectBorrow (oldvalue )) {
247
270
PyObject * old_obj = PyStackRef_AsPyObjectBorrow (fast [i ]);
248
271
if (old_obj != NULL && !_Py_IsImmortal (old_obj )) {
249
- if (frame -> f_overwritten_fast_locals == NULL ) {
250
- frame -> f_overwritten_fast_locals = PyList_New (0 );
251
- if (frame -> f_overwritten_fast_locals == NULL ) {
252
- return -1 ;
253
- }
254
- }
255
- if (PyList_Append (frame -> f_overwritten_fast_locals , old_obj ) < 0 ) {
272
+ if (add_overwritten_fast_local (frame , old_obj ) < 0 ) {
256
273
return -1 ;
257
274
}
258
275
PyStackRef_CLOSE (fast [i ]);
0 commit comments