File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -396,15 +396,16 @@ always available.
396396.. function :: getallocatedblocks()
397397
398398 Return the number of memory blocks currently allocated by the interpreter,
399- regardless of their size. This function is mainly useful for debugging
400- small memory leaks. Because of the interpreter's internal caches, the
401- result can vary from call to call; you may have to call
402- :func: `_clear_type_cache() ` to get more predictable results.
399+ regardless of their size. This function is mainly useful for tracking
400+ and debugging memory leaks. Because of the interpreter's internal
401+ caches, the result can vary from call to call; you may have to call
402+ :func: `_clear_type_cache() ` and :func: `gc.collect() ` to get more
403+ predictable results.
403404
404- .. versionadded :: 3.4
405+ If a Python build or implementation cannot reasonably compute this
406+ information, :func: `getallocatedblocks() ` is allowed to return 0 instead.
405407
406- .. impl-detail ::
407- Not all Python implementations may be able to return this information.
408+ .. versionadded :: 3.4
408409
409410
410411.. function :: getcheckinterval()
Original file line number Diff line number Diff line change 77import operator
88import codecs
99import gc
10+ import sysconfig
1011
1112# count the number of test runs, used to create unique
1213# strings to intern in test_intern()
@@ -616,9 +617,13 @@ def test_debugmallocstats(self):
616617 "sys.getallocatedblocks unavailable on this build" )
617618 def test_getallocatedblocks (self ):
618619 # Some sanity checks
620+ with_pymalloc = sysconfig .get_config_var ('WITH_PYMALLOC' )
619621 a = sys .getallocatedblocks ()
620622 self .assertIs (type (a ), int )
621- self .assertGreater (a , 0 )
623+ if with_pymalloc :
624+ self .assertGreater (a , 0 )
625+ else :
626+ self .assertEqual (a , 0 )
622627 try :
623628 # While we could imagine a Python session where the number of
624629 # multiple buffer objects would exceed the sharing of references,
Original file line number Diff line number Diff line change @@ -1316,6 +1316,13 @@ PyObject_Free(void *p)
13161316{
13171317 PyMem_FREE (p );
13181318}
1319+
1320+ Py_ssize_t
1321+ _Py_GetAllocatedBlocks (void )
1322+ {
1323+ return 0 ;
1324+ }
1325+
13191326#endif /* WITH_PYMALLOC */
13201327
13211328#ifdef PYMALLOC_DEBUG
You can’t perform that action at this time.
0 commit comments