Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 80777:c40f4c19d20b
Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Also, the ``-R`` option to regrtest uses this function to guard against memory allocation leaks.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sun, 09 Dec 2012 14:28:26 +0100 |
| parents | ceb0184c7f44 |
| children | 1da78c7d382b |
line wrap: on
line diff
--- a/Python/sysmodule.c Sun Dec 09 16:22:17 2012 +1000 +++ b/Python/sysmodule.c Sun Dec 09 14:28:26 2012 +0100 @@ -894,6 +894,19 @@ reference as an argument to getrefcount()." ); +static PyObject * +sys_getallocatedblocks(PyObject *self) +{ + return PyLong_FromSsize_t(_Py_GetAllocatedBlocks()); +} + +PyDoc_STRVAR(getallocatedblocks_doc, +"getallocatedblocks() -> integer\n\ +\n\ +Return the number of memory blocks currently allocated, regardless of their\n\ +size." +); + #ifdef COUNT_ALLOCS static PyObject * sys_getcounts(PyObject *self) @@ -1062,6 +1075,8 @@ {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, getdlopenflags_doc}, #endif + {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, + getallocatedblocks_doc}, #ifdef COUNT_ALLOCS {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, #endif
