in dicts and sets when computing the total number of references.
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 ,
/* 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);
#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;
#endif
#ifdef Py_REF_DEBUG
- fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
+ fprintf(stderr, "[%ld refs]\n", _Py_GetRefTotal());
#endif
#ifdef Py_TRACE_REFS
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;
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\