[Python-checkins] python/dist/src/Objects object.c,2.201,2.202

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sat, 22 Mar 2003 18:51:04 -0800


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

Modified Files:
	object.c 
Log Message:
When Py_TRACE_REFS is defined, a list of all live objects is maintained in
a doubly-linked list, exposed by sys.getobjects().  Unfortunately, it's not
really all live objects, and it seems my fate to bump into programs where
sys.gettotalrefcount() keeps going up but where the reference leaks aren't
accounted for by anything in the list of all objects.

This patch helps a little:  if COUNT_ALLOCS is also defined, from now on
type objects will also appear in this list, provided at least one object
of a type has been allocated.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.201
retrieving revision 2.202
diff -C2 -d -r2.201 -r2.202
*** object.c	17 Mar 2003 19:46:11 -0000	2.201
--- object.c	23 Mar 2003 02:51:01 -0000	2.202
***************
*** 18,21 ****
--- 18,26 ----
     Do not call them otherwise, they do not initialize the object! */
  
+ #ifdef Py_TRACE_REFS
+ /* Head of doubly-linked list of all objects. */
+ static PyObject refchain = {&refchain, &refchain};
+ #endif
+ 
  #ifdef COUNT_ALLOCS
  static PyTypeObject *type_list;
***************
*** 85,88 ****
--- 90,103 ----
  		Py_INCREF(tp);
  		type_list = tp;
+ #ifdef Py_REF_DEBUG
+ 		/* 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
  	}
  	tp->tp_allocs++;
***************
*** 1936,1941 ****
  
  #ifdef Py_TRACE_REFS
- 
- static PyObject refchain = {&refchain, &refchain};
  
  void
--- 1951,1954 ----