@@ -561,36 +561,25 @@ static PyGetSetDef frame_getsetlist[] = {
561
561
/* max value for numfree */
562
562
#define PyFrame_MAXFREELIST 200
563
563
564
- /* bpo-40521: frame free lists are shared by all interpreters. */
565
- #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
566
- # undef PyFrame_MAXFREELIST
567
- # define PyFrame_MAXFREELIST 0
568
- #endif
569
-
570
- #if PyFrame_MAXFREELIST > 0
571
- static PyFrameObject * free_list = NULL ;
572
- static int numfree = 0 ; /* number of frames currently in free_list */
573
- #endif
574
-
575
564
static void _Py_HOT_FUNCTION
576
565
frame_dealloc (PyFrameObject * f )
577
566
{
578
- PyObject * * p , * * valuestack ;
579
- PyCodeObject * co ;
580
-
581
- if (_PyObject_GC_IS_TRACKED (f ))
567
+ if (_PyObject_GC_IS_TRACKED (f )) {
582
568
_PyObject_GC_UNTRACK (f );
569
+ }
583
570
584
571
Py_TRASHCAN_SAFE_BEGIN (f )
585
572
/* Kill all local variables */
586
- valuestack = f -> f_valuestack ;
587
- for (p = f -> f_localsplus ; p < valuestack ; p ++ )
573
+ PyObject * * valuestack = f -> f_valuestack ;
574
+ for (PyObject * * p = f -> f_localsplus ; p < valuestack ; p ++ ) {
588
575
Py_CLEAR (* p );
576
+ }
589
577
590
578
/* Free stack */
591
579
if (f -> f_stacktop != NULL ) {
592
- for (p = valuestack ; p < f -> f_stacktop ; p ++ )
580
+ for (PyObject * * p = valuestack ; p < f -> f_stacktop ; p ++ ) {
593
581
Py_XDECREF (* p );
582
+ }
594
583
}
595
584
596
585
Py_XDECREF (f -> f_back );
@@ -599,19 +588,21 @@ frame_dealloc(PyFrameObject *f)
599
588
Py_CLEAR (f -> f_locals );
600
589
Py_CLEAR (f -> f_trace );
601
590
602
- co = f -> f_code ;
591
+ PyCodeObject * co = f -> f_code ;
603
592
if (co -> co_zombieframe == NULL ) {
604
593
co -> co_zombieframe = f ;
605
594
}
606
- #if PyFrame_MAXFREELIST > 0
607
- else if (numfree < PyFrame_MAXFREELIST ) {
608
- ++ numfree ;
609
- f -> f_back = free_list ;
610
- free_list = f ;
611
- }
612
- #endif
613
595
else {
614
- PyObject_GC_Del (f );
596
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
597
+ struct _Py_frame_state * state = & interp -> frame ;
598
+ if (state -> numfree < PyFrame_MAXFREELIST ) {
599
+ ++ state -> numfree ;
600
+ f -> f_back = state -> free_list ;
601
+ state -> free_list = f ;
602
+ }
603
+ else {
604
+ PyObject_GC_Del (f );
605
+ }
615
606
}
616
607
617
608
Py_DECREF (co );
@@ -789,21 +780,20 @@ frame_alloc(PyCodeObject *code)
789
780
Py_ssize_t ncells = PyTuple_GET_SIZE (code -> co_cellvars );
790
781
Py_ssize_t nfrees = PyTuple_GET_SIZE (code -> co_freevars );
791
782
Py_ssize_t extras = code -> co_stacksize + code -> co_nlocals + ncells + nfrees ;
792
- #if PyFrame_MAXFREELIST > 0
793
- if ( free_list == NULL )
794
- #endif
783
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
784
+ struct _Py_frame_state * state = & interp -> frame ;
785
+ if ( state -> free_list == NULL )
795
786
{
796
787
f = PyObject_GC_NewVar (PyFrameObject , & PyFrame_Type , extras );
797
788
if (f == NULL ) {
798
789
return NULL ;
799
790
}
800
791
}
801
- #if PyFrame_MAXFREELIST > 0
802
792
else {
803
- assert (numfree > 0 );
804
- -- numfree ;
805
- f = free_list ;
806
- free_list = free_list -> f_back ;
793
+ assert (state -> numfree > 0 );
794
+ -- state -> numfree ;
795
+ f = state -> free_list ;
796
+ state -> free_list = state -> free_list -> f_back ;
807
797
if (Py_SIZE (f ) < extras ) {
808
798
PyFrameObject * new_f = PyObject_GC_Resize (PyFrameObject , f , extras );
809
799
if (new_f == NULL ) {
@@ -814,7 +804,6 @@ frame_alloc(PyCodeObject *code)
814
804
}
815
805
_Py_NewReference ((PyObject * )f );
816
806
}
817
- #endif
818
807
819
808
f -> f_code = code ;
820
809
extras = code -> co_nlocals + ncells + nfrees ;
@@ -1183,34 +1172,33 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
1183
1172
1184
1173
/* Clear out the free list */
1185
1174
void
1186
- _PyFrame_ClearFreeList (void )
1175
+ _PyFrame_ClearFreeList (PyThreadState * tstate )
1187
1176
{
1188
- #if PyFrame_MAXFREELIST > 0
1189
- while (free_list != NULL ) {
1190
- PyFrameObject * f = free_list ;
1191
- free_list = free_list -> f_back ;
1177
+ struct _Py_frame_state * state = & tstate -> interp -> frame ;
1178
+ while (state -> free_list != NULL ) {
1179
+ PyFrameObject * f = state -> free_list ;
1180
+ state -> free_list = state -> free_list -> f_back ;
1192
1181
PyObject_GC_Del (f );
1193
- -- numfree ;
1182
+ -- state -> numfree ;
1194
1183
}
1195
- assert (numfree == 0 );
1196
- #endif
1184
+ assert (state -> numfree == 0 );
1197
1185
}
1198
1186
1199
1187
void
1200
- _PyFrame_Fini (void )
1188
+ _PyFrame_Fini (PyThreadState * tstate )
1201
1189
{
1202
- _PyFrame_ClearFreeList ();
1190
+ _PyFrame_ClearFreeList (tstate );
1203
1191
}
1204
1192
1205
1193
/* Print summary info about the state of the optimized allocator */
1206
1194
void
1207
1195
_PyFrame_DebugMallocStats (FILE * out )
1208
1196
{
1209
- #if PyFrame_MAXFREELIST > 0
1197
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
1198
+ struct _Py_frame_state * state = & interp -> frame ;
1210
1199
_PyDebugAllocatorStats (out ,
1211
1200
"free PyFrameObject" ,
1212
- numfree , sizeof (PyFrameObject ));
1213
- #endif
1201
+ state -> numfree , sizeof (PyFrameObject ));
1214
1202
}
1215
1203
1216
1204
0 commit comments