summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-12-09 13:28:26 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-12-09 13:28:26 (GMT)
commitf9d0b1256fd5a9ae90fa8e8418bd450ec6b7f5f2 (patch)
treefd5ad7ad717440f4586652180cb31a3cf2e52e97 /Python
parentb4b8f234d4407492c4493e3a16bc8263139c7869 (diff)
downloadcpython-f9d0b1256fd5a9ae90fa8e8418bd450ec6b7f5f2.zip
cpython-f9d0b1256fd5a9ae90fa8e8418bd450ec6b7f5f2.tar.gz
cpython-f9d0b1256fd5a9ae90fa8e8418bd450ec6b7f5f2.tar.bz2
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')
-rw-r--r--Python/pythonrun.c7
-rw-r--r--Python/sysmodule.c15
2 files changed, 19 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index dd32017..f0d8550 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -38,9 +38,10 @@
#ifndef Py_REF_DEBUG
#define PRINT_TOTAL_REFS()
#else /* Py_REF_DEBUG */
-#define PRINT_TOTAL_REFS() fprintf(stderr, \
- "[%" PY_FORMAT_SIZE_T "d refs]\n", \
- _Py_GetRefTotal())
+#define PRINT_TOTAL_REFS() fprintf(stderr, \
+ "[%" PY_FORMAT_SIZE_T "d refs, " \
+ "%" PY_FORMAT_SIZE_T "d blocks]\n", \
+ _Py_GetRefTotal(), _Py_GetAllocatedBlocks())
#endif
#ifdef __cplusplus
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 92c5b67..20792c2 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