[Python-checkins] python/dist/src/Modules gcmodule.c,2.48,2.49

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Mon, 01 Jul 2002 17:52:32 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv8407/python/Modules

Modified Files:
	gcmodule.c 
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: gcmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/gcmodule.c,v
retrieving revision 2.48
retrieving revision 2.49
diff -C2 -d -r2.48 -r2.49
*** gcmodule.c	1 Jul 2002 03:52:19 -0000	2.48
--- gcmodule.c	2 Jul 2002 00:52:30 -0000	2.49
***************
*** 83,88 ****
  
  /* Special gc_refs values. */
! #define GC_REACHABLE  -123
! #define GC_TENTATIVELY_UNREACHABLE -42
  
  #define IS_REACHABLE(o) ((AS_GC(o))->gc.gc_refs == GC_REACHABLE)
--- 83,89 ----
  
  /* Special gc_refs values. */
! #define GC_UNTRACKED			_PyGC_REFS_UNTRACKED
! #define GC_REACHABLE			_PyGC_REFS_REACHABLE
! #define GC_TENTATIVELY_UNREACHABLE	_PyGC_REFS_TENTATIVELY_UNREACHABLE
  
  #define IS_REACHABLE(o) ((AS_GC(o))->gc.gc_refs == GC_REACHABLE)
***************
*** 180,185 ****
  {
  	PyGC_Head *gc = containers->gc.gc_next;
! 	for (; gc != containers; gc = gc->gc.gc_next)
  		gc->gc.gc_refs = FROM_GC(gc)->ob_refcnt;
  }
  
--- 181,188 ----
  {
  	PyGC_Head *gc = containers->gc.gc_next;
! 	for (; gc != containers; gc = gc->gc.gc_next) {
! 		assert(gc->gc.gc_refs == GC_REACHABLE);
  		gc->gc.gc_refs = FROM_GC(gc)->ob_refcnt;
+ 	}
  }
  
***************
*** 223,227 ****
  visit_reachable(PyObject *op, PyGC_Head *reachable)
  {
! 	if (PyObject_IS_GC(op) && IS_TRACKED(op)) {
  		PyGC_Head *gc = AS_GC(op);
  		const int gc_refs = gc->gc.gc_refs;
--- 226,230 ----
  visit_reachable(PyObject *op, PyGC_Head *reachable)
  {
! 	if (PyObject_IS_GC(op)) {
  		PyGC_Head *gc = AS_GC(op);
  		const int gc_refs = gc->gc.gc_refs;
***************
*** 251,256 ****
  		 * If gc_refs == GC_REACHABLE, it's either in some other
  		 * generation so we don't care about it, or move_unreachable
! 		 * already dealt with it.
  		 */
  	}
  	return 0;
--- 254,265 ----
  		 * If gc_refs == GC_REACHABLE, it's either in some other
  		 * generation so we don't care about it, or move_unreachable
! 		 * already deat with it.
! 		 * If gc_refs == GC_UNTRACKED, it must be ignored.
  		 */
+ 		 else {
+ 		 	assert(gc_refs > 0
+ 		 	       || gc_refs == GC_REACHABLE
+ 		 	       || gc_refs == GC_UNTRACKED);
+ 		 }
  	}
  	return 0;
***************
*** 353,357 ****
  {
  	if (PyObject_IS_GC(op)) {
! 		if (IS_TRACKED(op) && IS_TENTATIVELY_UNREACHABLE(op)) {
  			PyGC_Head *gc = AS_GC(op);
  			gc_list_remove(gc);
--- 362,366 ----
  {
  	if (PyObject_IS_GC(op)) {
! 		if (IS_TENTATIVELY_UNREACHABLE(op)) {
  			PyGC_Head *gc = AS_GC(op);
  			gc_list_remove(gc);
***************
*** 967,970 ****
--- 976,980 ----
  		return PyErr_NoMemory();
  	g->gc.gc_next = NULL;
+ 	g->gc.gc_refs = GC_UNTRACKED;
  	generations[0].count++; /* number of allocated GC objects */
   	if (generations[0].count > generations[0].threshold &&