[Python-checkins] r45313 - in python/branches/release24-maint: Include/object.h Objects/dictobject.c Objects/object.c Python/pythonrun.c Python/sysmodule.c

armin.rigo python-checkins at python.org
Wed Apr 12 19:07:00 CEST 2006


Author: armin.rigo
Date: Wed Apr 12 19:06:58 2006
New Revision: 45313

Modified:
   python/branches/release24-maint/Include/object.h
   python/branches/release24-maint/Objects/dictobject.c
   python/branches/release24-maint/Objects/object.c
   python/branches/release24-maint/Python/pythonrun.c
   python/branches/release24-maint/Python/sysmodule.c
Log:
Ignore the references to the dummy objects used as deleted keys
in dicts and sets when computing the total number of references.


Modified: python/branches/release24-maint/Include/object.h
==============================================================================
--- python/branches/release24-maint/Include/object.h	(original)
+++ python/branches/release24-maint/Include/object.h	Wed Apr 12 19:06:58 2006
@@ -556,6 +556,8 @@
 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	,

Modified: python/branches/release24-maint/Objects/dictobject.c
==============================================================================
--- python/branches/release24-maint/Objects/dictobject.c	(original)
+++ python/branches/release24-maint/Objects/dictobject.c	Wed Apr 12 19:06:58 2006
@@ -115,6 +115,14 @@
 /* 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);

Modified: python/branches/release24-maint/Objects/object.c
==============================================================================
--- python/branches/release24-maint/Objects/object.c	(original)
+++ python/branches/release24-maint/Objects/object.c	Wed Apr 12 19:06:58 2006
@@ -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;
 

Modified: python/branches/release24-maint/Python/pythonrun.c
==============================================================================
--- python/branches/release24-maint/Python/pythonrun.c	(original)
+++ python/branches/release24-maint/Python/pythonrun.c	Wed Apr 12 19:06:58 2006
@@ -379,7 +379,7 @@
 #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 @@
 	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;

Modified: python/branches/release24-maint/Python/sysmodule.c
==============================================================================
--- python/branches/release24-maint/Python/sysmodule.c	(original)
+++ python/branches/release24-maint/Python/sysmodule.c	Wed Apr 12 19:06:58 2006
@@ -604,10 +604,9 @@
 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\


More information about the Python-checkins mailing list