Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 82956:367167f93c30
#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.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 26 Mar 2013 01:59:56 +0200 |
| parents | c40f4c19d20b |
| children | 6eacc6c134a5 |
line wrap: on
line diff
--- a/Python/pythonrun.c Mon Mar 25 18:20:40 2013 +0100 +++ b/Python/pythonrun.c Tue Mar 26 01:59:56 2013 +0200 @@ -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
