diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2000-06-20 08:12:48 +0000 |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2000-06-20 08:12:48 +0000 |
commit | 0b361fc63308b9eaf734cbda95ffdac3904d413b (patch) | |
tree | bebdfcc644b83b0937f086fb63c9dd50d77c03a6 /Python/sysmodule.c | |
parent | 6c852750f935a9e76c36c040a18335b4dcbf9c90 (diff) | |
download | cpython-0b361fc63308b9eaf734cbda95ffdac3904d413b.tar.gz |
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ea838ebd68..6219454ed6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -265,9 +265,21 @@ sys_getrefcount(self, args) PyObject *arg; if (!PyArg_ParseTuple(args, "O:getrefcount", &arg)) 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[] = "getrefcount(object) -> integer\n\ \n\ @@ -310,6 +322,7 @@ static PyMethodDef sys_methods[] = { #endif #ifdef Py_TRACE_REFS {"getobjects", _Py_GetObjects, 1}, + {"gettotalrefcount", sys_gettotalrefcount, 1}, #endif {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, #ifdef USE_MALLOPT |