]> granicus.if.org Git - python/commitdiff
bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510)
authorVictor Stinner <vstinner@redhat.com>
Tue, 13 Nov 2018 14:14:58 +0000 (15:14 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Nov 2018 14:14:58 +0000 (15:14 +0100)
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.

Lib/test/test_capi.py
Modules/_tracemalloc.c

index b3600ebe993de5ce8864fde39e37997b3de69128..3c8c3f02bf7874eb4f09221ad371bcd81d385094 100644 (file)
@@ -486,6 +486,8 @@ class PyMemDebugTests(unittest.TestCase):
                  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)
@@ -500,6 +502,8 @@ class PyMemDebugTests(unittest.TestCase):
                  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)
index 1005f2ea4d87d0a0f8f46c0da4fd18ce919cad33..c5d5671032ebf144562615e0cebad45be9fb520a 100644 (file)
@@ -1471,6 +1471,12 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
     traceback_t *traceback;
     int i;
 
+    if (!_Py_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;