|
28 | 28 | /* Get the object given the GC head */ |
29 | 29 | #define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1)) |
30 | 30 |
|
| 31 | +/* True if an object is tracked by the GC */ |
| 32 | +#define IS_TRACKED(o) ((AS_GC(o))->gc.gc_next != NULL) |
31 | 33 |
|
32 | 34 | /*** Global GC state ***/ |
33 | 35 |
|
@@ -73,6 +75,9 @@ static int debug; |
73 | 75 | /* Special gc_refs value */ |
74 | 76 | #define GC_MOVED -123 |
75 | 77 |
|
| 78 | +/* True if an object has been moved to the older generation */ |
| 79 | +#define IS_MOVED(o) ((AS_GC(o))->gc.gc_refs == GC_MOVED) |
| 80 | + |
76 | 81 | /* list of uncollectable objects */ |
77 | 82 | static PyObject *garbage; |
78 | 83 |
|
@@ -170,8 +175,7 @@ static int |
170 | 175 | visit_decref(PyObject *op, void *data) |
171 | 176 | { |
172 | 177 | if (op && PyObject_IS_GC(op)) { |
173 | | - PyGC_Head *gc = AS_GC(op); |
174 | | - if (gc->gc.gc_next != NULL) |
| 178 | + if (IS_TRACKED(op)) |
175 | 179 | AS_GC(op)->gc.gc_refs--; |
176 | 180 | } |
177 | 181 | return 0; |
@@ -212,8 +216,8 @@ static int |
212 | 216 | visit_move(PyObject *op, PyGC_Head *tolist) |
213 | 217 | { |
214 | 218 | if (PyObject_IS_GC(op)) { |
215 | | - PyGC_Head *gc = AS_GC(op); |
216 | | - if (gc->gc.gc_next != NULL && gc->gc.gc_refs != GC_MOVED) { |
| 219 | + if (IS_TRACKED(op) && !IS_MOVED(op)) { |
| 220 | + PyGC_Head *gc = AS_GC(op); |
217 | 221 | gc_list_remove(gc); |
218 | 222 | gc_list_append(gc, tolist); |
219 | 223 | gc->gc.gc_refs = GC_MOVED; |
|
856 | 860 | PyObject_GC_UnTrack(void *op) |
857 | 861 | { |
858 | 862 | #ifdef WITH_CYCLE_GC |
859 | | - PyGC_Head *gc = AS_GC(op); |
860 | | - if (gc->gc.gc_next != NULL) |
| 863 | + if (IS_TRACKED(op)) |
861 | 864 | _PyObject_GC_UNTRACK(op); |
862 | 865 | #endif |
863 | 866 | } |
@@ -941,7 +944,7 @@ PyObject_GC_Del(void *op) |
941 | 944 | { |
942 | 945 | #ifdef WITH_CYCLE_GC |
943 | 946 | PyGC_Head *g = AS_GC(op); |
944 | | - if (g->gc.gc_next != NULL) |
| 947 | + if (IS_TRACKED(op)) |
945 | 948 | gc_list_remove(g); |
946 | 949 | if (generations[0].count > 0) { |
947 | 950 | generations[0].count--; |
|
0 commit comments