[Python-checkins] bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510) (GH-10517)
Victor Stinner
webhook-mailer at python.org
Tue Nov 13 09:51:03 EST 2018
https://github.com/python/cpython/commit/d57a3e5d03efdda6247c27bd682872edf399d88b
commit: d57a3e5d03efdda6247c27bd682872edf399d88b
branch: 3.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-13T15:50:56+01:00
summary:
bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510) (GH-10517)
If tracemalloc is not tracing Python memory allocations,
_PyMem_DumpTraceback() now suggests to enable tracemalloc
to get the traceback where the memory block has been allocated.
files:
M Lib/test/test_capi.py
M Modules/_tracemalloc.c
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 49297f461dac..65e0795aba84 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -468,6 +468,8 @@ def test_buffer_overflow(self):
r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
r" Data at p: cb cb cb .*\n"
r"\n"
+ r"Enable tracemalloc to get the memory block allocation traceback\n"
+ r"\n"
r"Fatal Python error: bad trailing pad byte")
regex = regex.format(ptr=self.PTR_REGEX)
regex = re.compile(regex, flags=re.DOTALL)
@@ -482,6 +484,8 @@ def test_api_misuse(self):
r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
r" Data at p: cb cb cb .*\n"
r"\n"
+ r"Enable tracemalloc to get the memory block allocation traceback\n"
+ r"\n"
r"Fatal Python error: bad ID: Allocated using API 'm', verified using API 'r'\n")
regex = regex.format(ptr=self.PTR_REGEX)
self.assertRegex(out, regex)
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index e07022cce2bc..7f19c5598120 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -1490,6 +1490,12 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
traceback_t *traceback;
int i;
+ if (!tracemalloc_config.tracing) {
+ PUTS(fd, "Enable tracemalloc to get the memory block "
+ "allocation traceback\n\n");
+ return;
+ }
+
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
if (traceback == NULL)
return;
More information about the Python-checkins
mailing list