[Patches] New sys method to return total reference count in debug builds.

Mark Hammond mhammond@skippinet.com.au
Fri, 9 Jun 2000 15:39:36 +1000


Here is a revised patch for the description included below.  The revision
removes the casts, as discussed here.

If there are no comments over the next couple of days, I will check this
change in.

Mark.

> When recently tracking down leaks, I found the ability to see the total
> number of Python references incredibly useful - it made it quite
> trivial to
> see which functions were leaking Python object references.
>
> This information is exposed in certain builds to the C API, but
> previously
> wasn't exposed to Python.  This patch addresses this.  The
> function will be
> exposed in default debug builds on the Windows platform, and any other
> builds where Py_TRACE_REFS is defined.

diff -r2.64 sysmodule.c
268c268
< 	return PyInt_FromLong((long) arg->ob_refcnt);
---
> 	return PyInt_FromLong(arg->ob_refcnt);
270a271,282
> #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 */
>
312a325
> 	{"gettotalrefcount", sys_gettotalrefcount, 1},


Release info:

I confirm that, to the best of my knowledge and belief, this contribution
is free of any claims of third parties under copyright, patent or other
rights or interests ("claims").  To the extent that I have any such claims,
I hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide
license to reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part of the
Python software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize others
to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or not
to incorporate this contribution in the Python software and its related
documentation.  I further grant CNRI permission to use my name and other
identifying information provided to CNRI by me for use in connection with
the Python software and its related documentation.

Mark.