mirror of
https://github.com/python/cpython.git
synced 2025-09-15 05:06:12 +00:00
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Also removed a redundant cast from sys.getrefcount(), as discussed on the patches list.
This commit is contained in:
parent
abf17032a4
commit
440d898230
1 changed files with 14 additions and 1 deletions
|
@ -265,9 +265,21 @@ sys_getrefcount(self, args)
|
||||||
PyObject *arg;
|
PyObject *arg;
|
||||||
if (!PyArg_ParseTuple(args, "O:getrefcount", &arg))
|
if (!PyArg_ParseTuple(args, "O:getrefcount", &arg))
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyInt_FromLong((long) arg->ob_refcnt);
|
return PyInt_FromLong(arg->ob_refcnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Py_TRACE_REFS
|
||||||
|
static PyObject *
|
||||||
|
sys_gettotalrefcount(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
extern long _Py_RefTotal;
|
||||||
|
if (!PyArg_ParseTuple(args, ":gettotalrefcount"))
|
||||||
|
return NULL;
|
||||||
|
return PyInt_FromLong(_Py_RefTotal);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* Py_TRACE_REFS */
|
||||||
|
|
||||||
static char getrefcount_doc[] =
|
static char getrefcount_doc[] =
|
||||||
"getrefcount(object) -> integer\n\
|
"getrefcount(object) -> integer\n\
|
||||||
\n\
|
\n\
|
||||||
|
@ -310,6 +322,7 @@ static PyMethodDef sys_methods[] = {
|
||||||
#endif
|
#endif
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
{"getobjects", _Py_GetObjects, 1},
|
{"getobjects", _Py_GetObjects, 1},
|
||||||
|
{"gettotalrefcount", sys_gettotalrefcount, 1},
|
||||||
#endif
|
#endif
|
||||||
{"getrefcount", sys_getrefcount, 1, getrefcount_doc},
|
{"getrefcount", sys_getrefcount, 1, getrefcount_doc},
|
||||||
#ifdef USE_MALLOPT
|
#ifdef USE_MALLOPT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue