summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-03-23 03:33:13 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-03-23 03:33:13 (GMT)
commit36eb4dfb819dbfe90d82e0c6b58bd360c22bcc26 (patch)
tree03aa5497be9d977f26d423c36234145668c6f4e1 /Objects/object.c
parent3e40c7ff5bb54c4787290109b51394ad34ef815d (diff)
downloadcpython-36eb4dfb819dbfe90d82e0c6b58bd360c22bcc26.zip
cpython-36eb4dfb819dbfe90d82e0c6b58bd360c22bcc26.tar.gz
cpython-36eb4dfb819dbfe90d82e0c6b58bd360c22bcc26.tar.bz2
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.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/Objects/object.c b/Objects/object.c
index ecc25c7..059b36a 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -20,6 +20,16 @@ int Py_DivisionWarningFlag;
#ifdef Py_TRACE_REFS
/* 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
#ifdef COUNT_ALLOCS
@@ -91,12 +101,9 @@ inc_count(PyTypeObject *tp)
type_list = tp;
#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;
+ if (tp->_ob_prev == NULL) {
+ assert(tp->_ob_next == NULL);
+ _Py_AddToAllObjects((PyObject *)tp);
}
#endif
}
@@ -1956,10 +1963,7 @@ _Py_NewReference(PyObject *op)
{
_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_AddToAllObjects(op);
_Py_INC_TPALLOCS(op);
}