diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-03-23 02:51:01 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-03-23 02:51:01 (GMT) |
commit | 78be7993b64958585bafdced0c86c06fde8155fb (patch) | |
tree | 74bebff154ab7cadac8356d6e8bde221a6af30c9 /Objects/object.c | |
parent | 0529377cdfd6912a2450239c1b52ae53b09e1658 (diff) | |
download | cpython-78be7993b64958585bafdced0c86c06fde8155fb.zip cpython-78be7993b64958585bafdced0c86c06fde8155fb.tar.gz cpython-78be7993b64958585bafdced0c86c06fde8155fb.tar.bz2 |
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.
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Objects/object.c b/Objects/object.c index 9ce3de7..2332df8 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -17,6 +17,11 @@ int Py_DivisionWarningFlag; These are used by the individual routines for object creation. 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; extern int tuple_zero_allocs, fast_tuple_allocs; @@ -84,6 +89,16 @@ inc_count(PyTypeObject *tp) */ 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++; if (tp->tp_allocs - tp->tp_frees > tp->tp_maxalloc) @@ -1936,8 +1951,6 @@ _Py_ReadyTypes(void) #ifdef Py_TRACE_REFS -static PyObject refchain = {&refchain, &refchain}; - void _Py_NewReference(PyObject *op) { |