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

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

index 131812f93b2131c7149326591c276f288232d4aa..924480f888640e9fdd3b453df7c1074b61430bf4 100644 (file)
@@ -578,6 +578,9 @@ environment the global variable trick is not safe.)
 PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
 PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
                                            int lineno, PyObject *op);
+PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
+PyAPI_FUNC(PyObject *) _PySet_Dummy(void);
+PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
 #define _Py_INC_REFTOTAL       _Py_RefTotal++
 #define _Py_DEC_REFTOTAL       _Py_RefTotal--
 #define _Py_REF_DEBUG_COMMA    ,
index f6fa1eb9e4440af8b122c109d395d82f7cc93021..31ef958e63af6676b735f3086ac9b7d906b8bf7f 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 = NULL; /* 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 e15218fa2374405dd724649ecb649e586cb804a8..0ce4332f763163a1c356274ad3accaa364e599fb 100644 (file)
@@ -5,7 +5,24 @@
 
 #ifdef Py_REF_DEBUG
 Py_ssize_t _Py_RefTotal;
-#endif
+
+Py_ssize_t
+_Py_GetRefTotal(void)
+{
+       PyObject *o;
+       Py_ssize_t total = _Py_RefTotal;
+        /* ignore the references to the dummy object of the dicts and sets
+           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;
+       o = _PySet_Dummy();
+       if (o != NULL)
+               total -= o->ob_refcnt;
+       return total;
+}
+#endif /* Py_REF_DEBUG */
 
 int Py_DivisionWarningFlag;
 
index edc43df57469e4109c3d05b2210b4523bfed3f14..e7f6e09fec1b77fa2fad294d5f36f46b75444d50 100644 (file)
 /* Object used as dummy key to fill deleted entries */
 static PyObject *dummy = NULL; /* Initialized by first call to make_new_set() */
 
+#ifdef Py_REF_DEBUG
+PyObject *
+_PySet_Dummy(void)
+{
+       return dummy;
+}
+#endif
+
 #define INIT_NONZERO_SET_SLOTS(so) do {                                \
        (so)->table = (so)->smalltable;                         \
        (so)->mask = PySet_MINSIZE - 1;                         \
index 1aa6930435a79ea9c5245e4bbdf624745a5a7c87..818c7609018ac346067648ed9de10c0a09d5ad89 100644 (file)
@@ -34,7 +34,7 @@
 #else /* Py_REF_DEBUG */
 #define PRINT_TOTAL_REFS() fprintf(stderr,                             \
                                   "[%" PY_FORMAT_SIZE_T "d refs]\n",   \
-                                  _Py_RefTotal)
+                                  _Py_GetRefTotal())
 #endif
 
 extern char *Py_GetPath(void);
index 4a527424c4a13bc7dedbf4961ef475c7a3377ad0..cbf0d8f5e3d44a1417dd2b9c7341ddb781758898 100644 (file)
@@ -604,10 +604,9 @@ sys_getrefcount(PyObject *self, PyObject *arg)
 static PyObject *
 sys_gettotalrefcount(PyObject *self)
 {
-       return PyInt_FromSsize_t(_Py_RefTotal);
+       return PyInt_FromSsize_t(_Py_GetRefTotal());
 }
-
-#endif /* Py_TRACE_REFS */
+#endif /* Py_REF_DEBUG */
 
 PyDoc_STRVAR(getrefcount_doc,
 "getrefcount(object) -> integer\n\