summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-05-21 15:53:24 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-05-21 15:53:24 (GMT)
commita2b11ecb08d3a884726eaa4c3a0277bf005d6e19 (patch)
treebb124d7227072a8a5dc76c48e50b28389e4491d1
parent0ebac97058baad8250adf710f287e8fb8770f7fa (diff)
downloadcpython-a2b11ecb08d3a884726eaa4c3a0277bf005d6e19.zip
cpython-a2b11ecb08d3a884726eaa4c3a0277bf005d6e19.tar.gz
cpython-a2b11ecb08d3a884726eaa4c3a0277bf005d6e19.tar.bz2
Add IS_TRACKED and IS_MOVED macros. This makes the logic a little more clear.
-rw-r--r--Modules/gcmodule.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 2ae4d42..b334f9d 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -28,6 +28,8 @@
/* Get the object given the GC head */
#define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
+/* True if an object is tracked by the GC */
+#define IS_TRACKED(o) ((AS_GC(o))->gc.gc_next != NULL)
/*** Global GC state ***/
@@ -73,6 +75,9 @@ static int debug;
/* Special gc_refs value */
#define GC_MOVED -123
+/* True if an object has been moved to the older generation */
+#define IS_MOVED(o) ((AS_GC(o))->gc.gc_refs == GC_MOVED)
+
/* list of uncollectable objects */
static PyObject *garbage;
@@ -170,8 +175,7 @@ static int
visit_decref(PyObject *op, void *data)
{
if (op && PyObject_IS_GC(op)) {
- PyGC_Head *gc = AS_GC(op);
- if (gc->gc.gc_next != NULL)
+ if (IS_TRACKED(op))
AS_GC(op)->gc.gc_refs--;
}
return 0;
@@ -212,8 +216,8 @@ static int
visit_move(PyObject *op, PyGC_Head *tolist)
{
if (PyObject_IS_GC(op)) {
- PyGC_Head *gc = AS_GC(op);
- if (gc->gc.gc_next != NULL && gc->gc.gc_refs != GC_MOVED) {
+ if (IS_TRACKED(op) && !IS_MOVED(op)) {
+ PyGC_Head *gc = AS_GC(op);
gc_list_remove(gc);
gc_list_append(gc, tolist);
gc->gc.gc_refs = GC_MOVED;
@@ -856,8 +860,7 @@ void
PyObject_GC_UnTrack(void *op)
{
#ifdef WITH_CYCLE_GC
- PyGC_Head *gc = AS_GC(op);
- if (gc->gc.gc_next != NULL)
+ if (IS_TRACKED(op))
_PyObject_GC_UNTRACK(op);
#endif
}
@@ -941,7 +944,7 @@ PyObject_GC_Del(void *op)
{
#ifdef WITH_CYCLE_GC
PyGC_Head *g = AS_GC(op);
- if (g->gc.gc_next != NULL)
+ if (IS_TRACKED(op))
gc_list_remove(g);
if (generations[0].count > 0) {
generations[0].count--;