@@ -1044,9 +1044,20 @@ record_deallocation(PyThreadState *tstate)
1044
1044
}
1045
1045
1046
1046
static void
1047
- gc_collect_internal (PyInterpreterState * interp , struct collection_state * state )
1047
+ gc_collect_internal (PyInterpreterState * interp , struct collection_state * state , int generation )
1048
1048
{
1049
1049
_PyEval_StopTheWorld (interp );
1050
+
1051
+ // update collection and allocation counters
1052
+ if (generation + 1 < NUM_GENERATIONS ) {
1053
+ state -> gcstate -> old [generation ].count += 1 ;
1054
+ }
1055
+
1056
+ state -> gcstate -> young .count = 0 ;
1057
+ for (int i = 1 ; i <= generation ; ++ i ) {
1058
+ state -> gcstate -> old [i - 1 ].count = 0 ;
1059
+ }
1060
+
1050
1061
// merge refcounts for all queued objects
1051
1062
merge_all_queued_objects (interp , state );
1052
1063
process_delayed_frees (interp );
@@ -1115,7 +1126,6 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state)
1115
1126
static Py_ssize_t
1116
1127
gc_collect_main (PyThreadState * tstate , int generation , _PyGC_Reason reason )
1117
1128
{
1118
- int i ;
1119
1129
Py_ssize_t m = 0 ; /* # objects collected */
1120
1130
Py_ssize_t n = 0 ; /* # unreachable objects that couldn't be collected */
1121
1131
PyTime_t t1 = 0 ; /* initialize to prevent a compiler warning */
@@ -1161,23 +1171,14 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
1161
1171
PyDTrace_GC_START (generation );
1162
1172
}
1163
1173
1164
- /* update collection and allocation counters */
1165
- if (generation + 1 < NUM_GENERATIONS ) {
1166
- gcstate -> old [generation ].count += 1 ;
1167
- }
1168
- gcstate -> young .count = 0 ;
1169
- for (i = 1 ; i <= generation ; i ++ ) {
1170
- gcstate -> old [i - 1 ].count = 0 ;
1171
- }
1172
-
1173
1174
PyInterpreterState * interp = tstate -> interp ;
1174
1175
1175
1176
struct collection_state state = {
1176
1177
.interp = interp ,
1177
1178
.gcstate = gcstate ,
1178
1179
};
1179
1180
1180
- gc_collect_internal (interp , & state );
1181
+ gc_collect_internal (interp , & state , generation );
1181
1182
1182
1183
m = state .collected ;
1183
1184
n = state .uncollectable ;
0 commit comments