Mailing List Archive

python/dist/src/Include objimpl.h,2.53,2.54
Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv8407/python/Include

Modified Files:
objimpl.h
Log Message:
Reserved another gc_refs value for untracked objects. Every live gc
object should now have a well-defined gc_refs value, with clear transitions
among gc_refs states. As a result, none of the visit_XYZ traversal
callbacks need to check IS_TRACKED() anymore, and those tests were removed.
(They were already looking for objects with specific gc_refs states, and
the gc_refs state of an untracked object can no longer match any other
gc_refs state by accident.)
Added more asserts.
I expect that the gc_next == NULL indicator for an untracked object is
now redundant and can also be removed, but I ran out of time for this.


Index: objimpl.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/objimpl.h,v
retrieving revision 2.53
retrieving revision 2.54
diff -C2 -d -r2.53 -r2.54
*** objimpl.h 4 May 2002 05:36:06 -0000 2.53
--- objimpl.h 2 Jul 2002 00:52:30 -0000 2.54
***************
*** 263,272 ****
#define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)

/* Tell the GC to track this object. NB: While the object is tracked the
* collector it must be safe to call the ob_traverse method. */
#define _PyObject_GC_TRACK(o) do { \
PyGC_Head *g = _Py_AS_GC(o); \
! if (g->gc.gc_next != NULL) \
! Py_FatalError("GC object already in linked list"); \
g->gc.gc_next = _PyGC_generation0; \
g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
--- 263,278 ----
#define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)

+ #define _PyGC_REFS_UNTRACKED (-2)
+ #define _PyGC_REFS_REACHABLE (-3)
+ #define _PyGC_REFS_TENTATIVELY_UNREACHABLE (-4)
+
/* Tell the GC to track this object. NB: While the object is tracked the
* collector it must be safe to call the ob_traverse method. */
#define _PyObject_GC_TRACK(o) do { \
PyGC_Head *g = _Py_AS_GC(o); \
! if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \
! Py_FatalError("GC object already tracked"); \
! assert(g->gc.gc_refs == _PyGC_REFS_UNTRACKED); \
! g->gc.gc_refs = _PyGC_REFS_REACHABLE; \
g->gc.gc_next = _PyGC_generation0; \
g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
***************
*** 278,281 ****
--- 284,289 ----
#define _PyObject_GC_UNTRACK(o) do { \
PyGC_Head *g = _Py_AS_GC(o); \
+ assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \
+ g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \
g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \