mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
Following issue #13390, fix compilation --without-pymalloc, and make sys.getallocatedblocks() return 0 in that situation.
This commit is contained in:
parent
3438fa496d
commit
928405303d
3 changed files with 21 additions and 8 deletions
|
|
@ -396,16 +396,17 @@ always available.
|
||||||
.. function:: getallocatedblocks()
|
.. function:: getallocatedblocks()
|
||||||
|
|
||||||
Return the number of memory blocks currently allocated by the interpreter,
|
Return the number of memory blocks currently allocated by the interpreter,
|
||||||
regardless of their size. This function is mainly useful for debugging
|
regardless of their size. This function is mainly useful for tracking
|
||||||
small memory leaks. Because of the interpreter's internal caches, the
|
and debugging memory leaks. Because of the interpreter's internal
|
||||||
result can vary from call to call; you may have to call
|
caches, the result can vary from call to call; you may have to call
|
||||||
:func:`_clear_type_cache()` to get more predictable results.
|
:func:`_clear_type_cache()` and :func:`gc.collect()` to get more
|
||||||
|
predictable results.
|
||||||
|
|
||||||
|
If a Python build or implementation cannot reasonably compute this
|
||||||
|
information, :func:`getallocatedblocks()` is allowed to return 0 instead.
|
||||||
|
|
||||||
.. versionadded:: 3.4
|
.. versionadded:: 3.4
|
||||||
|
|
||||||
.. impl-detail::
|
|
||||||
Not all Python implementations may be able to return this information.
|
|
||||||
|
|
||||||
|
|
||||||
.. function:: getcheckinterval()
|
.. function:: getcheckinterval()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import warnings
|
||||||
import operator
|
import operator
|
||||||
import codecs
|
import codecs
|
||||||
import gc
|
import gc
|
||||||
|
import sysconfig
|
||||||
|
|
||||||
# count the number of test runs, used to create unique
|
# count the number of test runs, used to create unique
|
||||||
# strings to intern in test_intern()
|
# strings to intern in test_intern()
|
||||||
|
|
@ -616,9 +617,13 @@ class SysModuleTest(unittest.TestCase):
|
||||||
"sys.getallocatedblocks unavailable on this build")
|
"sys.getallocatedblocks unavailable on this build")
|
||||||
def test_getallocatedblocks(self):
|
def test_getallocatedblocks(self):
|
||||||
# Some sanity checks
|
# Some sanity checks
|
||||||
|
with_pymalloc = sysconfig.get_config_var('WITH_PYMALLOC')
|
||||||
a = sys.getallocatedblocks()
|
a = sys.getallocatedblocks()
|
||||||
self.assertIs(type(a), int)
|
self.assertIs(type(a), int)
|
||||||
|
if with_pymalloc:
|
||||||
self.assertGreater(a, 0)
|
self.assertGreater(a, 0)
|
||||||
|
else:
|
||||||
|
self.assertEqual(a, 0)
|
||||||
try:
|
try:
|
||||||
# While we could imagine a Python session where the number of
|
# While we could imagine a Python session where the number of
|
||||||
# multiple buffer objects would exceed the sharing of references,
|
# multiple buffer objects would exceed the sharing of references,
|
||||||
|
|
|
||||||
|
|
@ -1316,6 +1316,13 @@ PyObject_Free(void *p)
|
||||||
{
|
{
|
||||||
PyMem_FREE(p);
|
PyMem_FREE(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Py_ssize_t
|
||||||
|
_Py_GetAllocatedBlocks(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* WITH_PYMALLOC */
|
#endif /* WITH_PYMALLOC */
|
||||||
|
|
||||||
#ifdef PYMALLOC_DEBUG
|
#ifdef PYMALLOC_DEBUG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue