]> granicus.if.org Git - python/commitdiff
Refactored some of the Py_TRACE_REFS code. New private API function
authorTim Peters <tim.peters@gmail.com>
Sun, 23 Mar 2003 03:33:13 +0000 (03:33 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 23 Mar 2003 03:33:13 +0000 (03:33 +0000)
_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.

Include/object.h
Objects/object.c
Objects/typeobject.c

index 33e57a4659435f2767886adb04dd3541b3e9e23b..89445c0976b83fa4cd5861c749488c3c555c1683 100644 (file)
@@ -582,6 +582,7 @@ PyAPI_FUNC(void) _Py_NewReference(PyObject *);
 PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
 PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
 PyAPI_FUNC(void) _Py_PrintReferences(FILE *);
+PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *);
 
 #else
 /* Without Py_TRACE_REFS, there's little enough to do that we expand code
index ecc25c7c5ec7ff2d222549f66d1da10c11b8c4a0..059b36ab0a60700281766429681b229a42ce7d91 100644 (file)
@@ -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);
 }
 
index b0297774b5c21fc860511442f3c218d5f5da0e14..c2ed180499e60e5cb6a69ac9f651e32a4657d7e6 100644 (file)
@@ -3052,6 +3052,18 @@ PyType_Ready(PyTypeObject *type)
 
        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;
        if (base == NULL && type != &PyBaseObject_Type)