comparison Python/sysmodule.c @ 12965:04c89d77dfdb legacy-trunk

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.
author Mark Hammond <mhammond@skippinet.com.au>
date Tue, 20 Jun 2000 08:12:48 +0000
parents 78231bbe605d
children 8c8de5b736dc
comparison
equal deleted inserted replaced
12964:93661d0eb5cc 12965:04c89d77dfdb
263 PyObject *args; 263 PyObject *args;
264 { 264 {
265 PyObject *arg; 265 PyObject *arg;
266 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg)) 266 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg))
267 return NULL; 267 return NULL;
268 return PyInt_FromLong((long) arg->ob_refcnt); 268 return PyInt_FromLong(arg->ob_refcnt);
269 } 269 }
270
271 #ifdef Py_TRACE_REFS
272 static PyObject *
273 sys_gettotalrefcount(PyObject *self, PyObject *args)
274 {
275 extern long _Py_RefTotal;
276 if (!PyArg_ParseTuple(args, ":gettotalrefcount"))
277 return NULL;
278 return PyInt_FromLong(_Py_RefTotal);
279 }
280
281 #endif /* Py_TRACE_REFS */
270 282
271 static char getrefcount_doc[] = 283 static char getrefcount_doc[] =
272 "getrefcount(object) -> integer\n\ 284 "getrefcount(object) -> integer\n\
273 \n\ 285 \n\
274 Return the current reference count for the object. This includes the\n\ 286 Return the current reference count for the object. This includes the\n\
308 #ifdef DYNAMIC_EXECUTION_PROFILE 320 #ifdef DYNAMIC_EXECUTION_PROFILE
309 {"getdxp", _Py_GetDXProfile, 1}, 321 {"getdxp", _Py_GetDXProfile, 1},
310 #endif 322 #endif
311 #ifdef Py_TRACE_REFS 323 #ifdef Py_TRACE_REFS
312 {"getobjects", _Py_GetObjects, 1}, 324 {"getobjects", _Py_GetObjects, 1},
325 {"gettotalrefcount", sys_gettotalrefcount, 1},
313 #endif 326 #endif
314 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, 327 {"getrefcount", sys_getrefcount, 1, getrefcount_doc},
315 #ifdef USE_MALLOPT 328 #ifdef USE_MALLOPT
316 {"mdebug", sys_mdebug, 1}, 329 {"mdebug", sys_mdebug, 1},
317 #endif 330 #endif