]> granicus.if.org Git - python/commitdiff
Following issue #13390, fix compilation --without-pymalloc, and make sys.getallocated...
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 17 Dec 2012 22:05:59 +0000 (23:05 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 17 Dec 2012 22:05:59 +0000 (23:05 +0100)
Doc/library/sys.rst
Lib/test/test_sys.py
Objects/obmalloc.c

index ee1f2b23a6dced206a2e8e98d7f9a838a5427c4d..a906cde2d1172025e7c009994de81309c74c7c8d 100644 (file)
@@ -396,15 +396,16 @@ always available.
 .. function:: getallocatedblocks()
 
    Return the number of memory blocks currently allocated by the interpreter,
-   regardless of their size.  This function is mainly useful for debugging
-   small memory leaks.  Because of the interpreter's internal caches, the
-   result can vary from call to call; you may have to call
-   :func:`_clear_type_cache()` to get more predictable results.
+   regardless of their size.  This function is mainly useful for tracking
+   and debugging memory leaks.  Because of the interpreter's internal
+   caches, the result can vary from call to call; you may have to call
+   :func:`_clear_type_cache()` and :func:`gc.collect()` to get more
+   predictable results.
 
-   .. versionadded:: 3.4
+   If a Python build or implementation cannot reasonably compute this
+   information, :func:`getallocatedblocks()` is allowed to return 0 instead.
 
-   .. impl-detail::
-      Not all Python implementations may be able to return this information.
+   .. versionadded:: 3.4
 
 
 .. function:: getcheckinterval()
index 055592ba0704d63ce043ac82b15e780c913088a0..41f1439741b20692e62d5791945f75ca8be0b02e 100644 (file)
@@ -7,6 +7,7 @@ import warnings
 import operator
 import codecs
 import gc
+import sysconfig
 
 # count the number of test runs, used to create unique
 # strings to intern in test_intern()
@@ -616,9 +617,13 @@ class SysModuleTest(unittest.TestCase):
                          "sys.getallocatedblocks unavailable on this build")
     def test_getallocatedblocks(self):
         # Some sanity checks
+        with_pymalloc = sysconfig.get_config_var('WITH_PYMALLOC')
         a = sys.getallocatedblocks()
         self.assertIs(type(a), int)
-        self.assertGreater(a, 0)
+        if with_pymalloc:
+            self.assertGreater(a, 0)
+        else:
+            self.assertEqual(a, 0)
         try:
             # While we could imagine a Python session where the number of
             # multiple buffer objects would exceed the sharing of references,
index c82c978e4dab464a8fcf6ffb4b512a37b0f9c552..bbe2805bd1621ae0d2c35e1e8040f5d16b8457bd 100644 (file)
@@ -1316,6 +1316,13 @@ PyObject_Free(void *p)
 {
     PyMem_FREE(p);
 }
+
+Py_ssize_t
+_Py_GetAllocatedBlocks(void)
+{
+    return 0;
+}
+
 #endif /* WITH_PYMALLOC */
 
 #ifdef PYMALLOC_DEBUG