summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-03-25 23:59:56 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-03-25 23:59:56 (GMT)
commit1f8898a5916b942c86ee8716c37d2db388e7bf2f (patch)
tree100c2cdc7d7628190538154de04512cf5c7fe345 /Python
parent84e431648917234f8e3823b60f31d701491a988e (diff)
downloadcpython-1f8898a5916b942c86ee8716c37d2db388e7bf2f.zip
cpython-1f8898a5916b942c86ee8716c37d2db388e7bf2f.tar.gz
cpython-1f8898a5916b942c86ee8716c37d2db388e7bf2f.tar.bz2
#17323: The "[X refs, Y blocks]" printed by debug builds has been disabled by default. It can be re-enabled with the `-X showrefcount` option.
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index f0d8550..751008a 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -35,13 +35,29 @@
#define PATH_MAX MAXPATHLEN
#endif
+#ifdef Py_REF_DEBUG
+void _print_total_refs() {
+ PyObject *xoptions, *key, *value;
+ xoptions = PySys_GetXOptions();
+ if (xoptions == NULL)
+ return;
+ key = PyUnicode_FromString("showrefcount");
+ if (key == NULL)
+ return;
+ value = PyDict_GetItem(xoptions, key);
+ Py_DECREF(key);
+ if (value == Py_True)
+ fprintf(stderr,
+ "[%" PY_FORMAT_SIZE_T "d refs, "
+ "%" PY_FORMAT_SIZE_T "d blocks]\n",
+ _Py_GetRefTotal(), _Py_GetAllocatedBlocks());
+}
+#endif
+
#ifndef Py_REF_DEBUG
#define PRINT_TOTAL_REFS()
#else /* Py_REF_DEBUG */
-#define PRINT_TOTAL_REFS() fprintf(stderr, \
- "[%" PY_FORMAT_SIZE_T "d refs, " \
- "%" PY_FORMAT_SIZE_T "d blocks]\n", \
- _Py_GetRefTotal(), _Py_GetAllocatedBlocks())
+#define PRINT_TOTAL_REFS() _print_total_refs()
#endif
#ifdef __cplusplus