]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510) (GH-10518)
authorVictor Stinner <vstinner@redhat.com>
Tue, 13 Nov 2018 15:13:17 +0000 (16:13 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Nov 2018 15:13:17 +0000 (16:13 +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 ae9e08a09b1edbe14e02908991af00497d291370..947da8c562331f7f3e8e86ba844fd428f1dc4821 100644 (file)
@@ -534,6 +534,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)
@@ -548,6 +550,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 4f3bb5463f03866fa11b8afce6050ff87786a2a6..a61bdb62fb524abfa7de802fd8e41b7e2c663c59 100644 (file)
@@ -1492,6 +1492,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;