diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-09 14:28:26 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-09 14:28:26 +0100 |
commit | 350e0ff264038e3790d0182134de7959965dea7d (patch) | |
tree | da900c8d363a534757cb8e099b92201340f7acf3 /Python/sysmodule.c | |
parent | 4857b8a30dddee2350b0d996b9d83a7d833eb071 (diff) | |
download | cpython-350e0ff264038e3790d0182134de7959965dea7d.tar.gz |
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 92c5b67611..20792c243c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -894,6 +894,19 @@ one higher than you might expect, because it includes the (temporary)\n\ 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 @@ static PyMethodDef sys_methods[] = { {"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 |