mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Ignore the references to the dummy objects used as deleted keys
in dicts and sets when computing the total number of references.
This commit is contained in:
parent
314fce92dd
commit
e170937af6
6 changed files with 40 additions and 5 deletions
|
@ -578,6 +578,9 @@ environment the global variable trick is not safe.)
|
||||||
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
|
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
|
||||||
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
|
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
|
||||||
int lineno, PyObject *op);
|
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_INC_REFTOTAL _Py_RefTotal++
|
||||||
#define _Py_DEC_REFTOTAL _Py_RefTotal--
|
#define _Py_DEC_REFTOTAL _Py_RefTotal--
|
||||||
#define _Py_REF_DEBUG_COMMA ,
|
#define _Py_REF_DEBUG_COMMA ,
|
||||||
|
|
|
@ -115,6 +115,14 @@ equally good collision statistics, needed less code & used less memory.
|
||||||
/* Object used as dummy key to fill deleted entries */
|
/* Object used as dummy key to fill deleted entries */
|
||||||
static PyObject *dummy = NULL; /* Initialized by first call to newdictobject() */
|
static PyObject *dummy = NULL; /* Initialized by first call to newdictobject() */
|
||||||
|
|
||||||
|
#ifdef Py_REF_DEBUG
|
||||||
|
PyObject *
|
||||||
|
_PyDict_Dummy(void)
|
||||||
|
{
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* forward declarations */
|
/* forward declarations */
|
||||||
static dictentry *
|
static dictentry *
|
||||||
lookdict_string(dictobject *mp, PyObject *key, long hash);
|
lookdict_string(dictobject *mp, PyObject *key, long hash);
|
||||||
|
|
|
@ -5,7 +5,24 @@
|
||||||
|
|
||||||
#ifdef Py_REF_DEBUG
|
#ifdef Py_REF_DEBUG
|
||||||
Py_ssize_t _Py_RefTotal;
|
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;
|
int Py_DivisionWarningFlag;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,14 @@
|
||||||
/* Object used as dummy key to fill deleted entries */
|
/* Object used as dummy key to fill deleted entries */
|
||||||
static PyObject *dummy = NULL; /* Initialized by first call to make_new_set() */
|
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 { \
|
#define INIT_NONZERO_SET_SLOTS(so) do { \
|
||||||
(so)->table = (so)->smalltable; \
|
(so)->table = (so)->smalltable; \
|
||||||
(so)->mask = PySet_MINSIZE - 1; \
|
(so)->mask = PySet_MINSIZE - 1; \
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#else /* Py_REF_DEBUG */
|
#else /* Py_REF_DEBUG */
|
||||||
#define PRINT_TOTAL_REFS() fprintf(stderr, \
|
#define PRINT_TOTAL_REFS() fprintf(stderr, \
|
||||||
"[%" PY_FORMAT_SIZE_T "d refs]\n", \
|
"[%" PY_FORMAT_SIZE_T "d refs]\n", \
|
||||||
_Py_RefTotal)
|
_Py_GetRefTotal())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char *Py_GetPath(void);
|
extern char *Py_GetPath(void);
|
||||||
|
|
|
@ -604,10 +604,9 @@ sys_getrefcount(PyObject *self, PyObject *arg)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
sys_gettotalrefcount(PyObject *self)
|
sys_gettotalrefcount(PyObject *self)
|
||||||
{
|
{
|
||||||
return PyInt_FromSsize_t(_Py_RefTotal);
|
return PyInt_FromSsize_t(_Py_GetRefTotal());
|
||||||
}
|
}
|
||||||
|
#endif /* Py_REF_DEBUG */
|
||||||
#endif /* Py_TRACE_REFS */
|
|
||||||
|
|
||||||
PyDoc_STRVAR(getrefcount_doc,
|
PyDoc_STRVAR(getrefcount_doc,
|
||||||
"getrefcount(object) -> integer\n\
|
"getrefcount(object) -> integer\n\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue