]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Ignore the references to the dummy objects used as deleted keys
authorArmin Rigo <arigo@tunes.org>
Wed, 12 Apr 2006 17:06:58 +0000 (17:06 +0000)
committerArmin Rigo <arigo@tunes.org>
Wed, 12 Apr 2006 17:06:58 +0000 (17:06 +0000)
in dicts and sets when computing the total number of references.

Include/object.h
Objects/dictobject.c
Objects/object.c
Python/pythonrun.c
Python/sysmodule.c

index fd7c235cd40e6eac220c9a770f686b1c3b9fb61e..2706d978e0bf75835d21b7a082d08e412cc45eb2 100644 (file)
@@ -556,6 +556,8 @@ environment the global variable trick is not safe.)
 PyAPI_DATA(long) _Py_RefTotal;
 PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
                                            int lineno, PyObject *op);
+PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
+PyAPI_FUNC(long) _Py_GetRefTotal(void);
 #define _Py_INC_REFTOTAL       _Py_RefTotal++
 #define _Py_DEC_REFTOTAL       _Py_RefTotal--
 #define _Py_REF_DEBUG_COMMA    ,
index 4e9d183615f1be2a3a9af9d1903bec7635e66089..18d8d5c1afa14f41df6e2ca3adf52338ef4ea176 100644 (file)
@@ -115,6 +115,14 @@ equally good collision statistics, needed less code & used less memory.
 /* Object used as dummy key to fill deleted entries */
 static PyObject *dummy; /* Initialized by first call to newdictobject() */
 
+#ifdef Py_REF_DEBUG
+PyObject *
+_PyDict_Dummy(void)
+{
+       return dummy;
+}
+#endif
+
 /* forward declarations */
 static dictentry *
 lookdict_string(dictobject *mp, PyObject *key, long hash);
index 7dbd554dffc467c32e2858dac8e6be93925b98e0..7cc0ab760d755a0b9ff25b2023b3026e415c7104 100644 (file)
@@ -5,7 +5,20 @@
 
 #ifdef Py_REF_DEBUG
 long _Py_RefTotal;
-#endif
+long
+_Py_GetRefTotal(void)
+{
+       PyObject *o;
+       long total = _Py_RefTotal;
+        /* ignore the references to the dummy object of the dicts
+           because they are not reliable and not useful (now that the
+           hash table code is well-tested) */
+       o = _PyDict_Dummy();
+       if (o != NULL)
+               total -= o->ob_refcnt;
+       return total;
+}
+#endif /* Py_REF_DEBUG */
 
 int Py_DivisionWarningFlag;
 
index 3317e551982581675d0747bc2a369765ac5d1b11..e093dc52981a3e129aad869e01c25867643be11a 100644 (file)
@@ -379,7 +379,7 @@ Py_Finalize(void)
 #endif
 
 #ifdef Py_REF_DEBUG
-       fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
+       fprintf(stderr, "[%ld refs]\n", _Py_GetRefTotal());
 #endif
 
 #ifdef Py_TRACE_REFS
@@ -694,7 +694,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag
        for (;;) {
                ret = PyRun_InteractiveOneFlags(fp, filename, flags);
 #ifdef Py_REF_DEBUG
-               fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
+               fprintf(stderr, "[%ld refs]\n", _Py_GetRefTotal());
 #endif
                if (ret == E_EOF)
                        return 0;
index 0775bb83c614987f7247884393cba3cf0e5e6fbe..1ce016f3f7a1dfcbb25dde44a8bd0c0df2ab4d6c 100644 (file)
@@ -604,10 +604,9 @@ sys_getrefcount(PyObject *self, PyObject *arg)
 static PyObject *
 sys_gettotalrefcount(PyObject *self)
 {
-       return PyInt_FromLong(_Py_RefTotal);
+       return PyInt_FromLong(_Py_GetRefTotal());
 }
-
-#endif /* Py_TRACE_REFS */
+#endif /* Py_REF_DEBUG */
 
 PyDoc_STRVAR(getrefcount_doc,
 "getrefcount(object) -> integer\n\