diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-04-29 10:23:31 -0400 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-04-29 10:23:31 -0400 |
commit | 9f4d539f55e6d1b1e6ebf96554e0dc72c46670fd (patch) | |
tree | 5deadc71564ef6bce38b7707a244d96ba5e64da9 /Python/pythonrun.c | |
parent | d322109d564f5c3e5704c110d50e14d79a11d2c3 (diff) | |
parent | 169d76b194ffd877b08c6cd2f52130eb9469d788 (diff) | |
download | cpython-9f4d539f55e6d1b1e6ebf96554e0dc72c46670fd.tar.gz |
merge 3.3 (#17863)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ee6071e631..b92a8bd9b4 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -35,12 +35,30 @@ #define PATH_MAX MAXPATHLEN #endif +#ifdef Py_REF_DEBUG +static +void _print_total_refs(void) { + 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]\n", \ - _Py_GetRefTotal()) +#define PRINT_TOTAL_REFS() _print_total_refs() #endif #ifdef __cplusplus |