[Python-checkins] python/dist/src/Objects object.c,2.203,2.204 typeobject.c,2.216,2.217

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sat, 22 Mar 2003 19:33:16 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv30969/python/Objects

Modified Files:
	object.c typeobject.c 
Log Message:
Refactored some of the Py_TRACE_REFS code.  New private API function
_Py_AddToAllObjects() that simply inserts an object at the front of
the doubly-linked list of all objects.  Changed PyType_Ready() (the
 closest thing we've got to a choke point for type objects) to call
that.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.203
retrieving revision 2.204
diff -C2 -d -r2.203 -r2.204
*** object.c	23 Mar 2003 03:04:32 -0000	2.203
--- object.c	23 Mar 2003 03:33:13 -0000	2.204
***************
*** 21,24 ****
--- 21,34 ----
  /* Head of doubly-linked list of all objects. */
  static PyObject refchain = {&refchain, &refchain};
+ 
+ /* Insert op at the fron of the doubly-linked list of all objects. */
+ void
+ _Py_AddToAllObjects(PyObject *op)
+ {
+ 	op->_ob_next = refchain._ob_next;
+ 	op->_ob_prev = &refchain;
+ 	refchain._ob_next->_ob_prev = op;
+ 	refchain._ob_next = op;
+ }
  #endif
  
***************
*** 92,101 ****
  #ifdef Py_TRACE_REFS
  		/* Also insert in the doubly-linked list of all objects. */
! 		if (tp->_ob_next == NULL) {
! 			PyObject *op = (PyObject *)tp;
! 			op->_ob_next = refchain._ob_next;
! 			op->_ob_prev = &refchain;
! 			refchain._ob_next->_ob_prev = op;
! 			refchain._ob_next = op;
  		}
  #endif
--- 102,108 ----
  #ifdef Py_TRACE_REFS
  		/* Also insert in the doubly-linked list of all objects. */
! 		if (tp->_ob_prev == NULL) {
! 			assert(tp->_ob_next == NULL);
! 			_Py_AddToAllObjects((PyObject *)tp);
  		}
  #endif
***************
*** 1957,1964 ****
  	_Py_INC_REFTOTAL;
  	op->ob_refcnt = 1;
! 	op->_ob_next = refchain._ob_next;
! 	op->_ob_prev = &refchain;
! 	refchain._ob_next->_ob_prev = op;
! 	refchain._ob_next = op;
  	_Py_INC_TPALLOCS(op);
  }
--- 1964,1968 ----
  	_Py_INC_REFTOTAL;
  	op->ob_refcnt = 1;
! 	_Py_AddToAllObjects(op);
  	_Py_INC_TPALLOCS(op);
  }

Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.216
retrieving revision 2.217
diff -C2 -d -r2.216 -r2.217
*** typeobject.c	12 Mar 2003 04:25:42 -0000	2.216
--- typeobject.c	23 Mar 2003 03:33:13 -0000	2.217
***************
*** 3053,3056 ****
--- 3053,3068 ----
  	type->tp_flags |= Py_TPFLAGS_READYING;
  
+ #ifdef Py_TRACE_REFS
+ 	/* PyType_Ready is the closest thing we have to a choke point
+ 	 * for type objects, so is the best place I can think of to try
+ 	 * to get type objects into the doubly-linked list of all objects.
+ 	 * Still, not all type objects go thru PyType_Ready.
+ 	 */
+ 	 if (type->_ob_next == NULL) {
+ 	 	assert(type->_ob_prev == NULL);
+ 		_Py_AddToAllObjects((PyObject *)type);
+ 	}
+ #endif
+ 
  	/* Initialize tp_base (defaults to BaseObject unless that's us) */
  	base = type->tp_base;