Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ The next fields, up to and including :c:member:`~PyTypeObject.tp_weaklist`, only
The remaining fields are only defined if the feature test macro
:const:`COUNT_ALLOCS` is defined, and are for internal use only. They are
documented here for completeness. None of these fields are inherited by
subtypes.
subtypes. See the :envvar:`PYTHONSHOWALLOCCOUNT` environment variable.


.. c:member:: Py_ssize_t PyTypeObject.tp_allocs
Expand Down
7 changes: 7 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,13 @@ if Python was configured with the ``--with-pydebug`` build option.
If set, Python will print memory allocation statistics every time a new
object arena is created, and on shutdown.

.. envvar:: PYTHONSHOWALLOCCOUNT

If set and Python was compiled with ``COUNT_ALLOCS`` defined, Python will
dump allocations counts into stderr on shutdown.

.. versionadded:: 2.7.15

.. envvar:: PYTHONSHOWREFCOUNT

If set, Python will print the total reference count when the program
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,9 @@ def py3k_bytes(b):
except TypeError:
return bytes(b)

requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'),
'types are immortal if COUNT_ALLOCS is defined')

def args_from_interpreter_flags():
"""Return a list of command-line arguments reproducing the current
settings in sys.flags."""
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class C(A, B):
C()
self.assertEqual(B.counter, 1)

@test_support.requires_type_collecting
def test_cache_leak(self):
# See issue #2521.
class A(object):
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_gc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from test.test_support import verbose, run_unittest, start_threads
from test.support import (verbose, run_unittest, start_threads,
requires_type_collecting)
import sys
import time
import gc
Expand Down Expand Up @@ -90,6 +91,7 @@ class A:
del a
self.assertNotEqual(gc.collect(), 0)

@requires_type_collecting
def test_newinstance(self):
class A(object):
pass
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def check_leak(self, code, what):
self.assertIn(line2, reflog)

@unittest.skipUnless(Py_DEBUG, 'need a debug build')
@support.requires_type_collecting
def test_huntrleaks(self):
# test --huntrleaks
code = textwrap.dedent("""
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,10 @@ def delx(self): del self.__x
# tupleiterator
check(iter(()), size('lP'))
# type
s = vsize('P2P15Pl4PP9PP11PI' # PyTypeObject
fmt = 'P2P15Pl4PP9PP11PI'
if hasattr(sys, 'getcounts'):
fmt += '3P2P'
s = vsize(fmt + # PyTypeObject
'39P' # PyNumberMethods
'3P' # PyMappingMethods
'10P' # PySequenceMethods
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_weakref.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ class D:
del c1, c2, C, D
gc.collect()

@test_support.requires_type_collecting
def test_callback_in_cycle_resurrection(self):
import gc

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add a new PYTHONSHOWALLOCCOUNT environment variable. When Python is compiled
with COUNT_ALLOCS, PYTHONSHOWALLOCCOUNT now has to be set to dump allocation
counts into stderr on shutdown. Moreover, allocations statistics are now dumped
into stderr rather than stdout.
4 changes: 3 additions & 1 deletion Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ Py_Finalize(void)

/* Debugging stuff */
#ifdef COUNT_ALLOCS
dump_counts(stdout);
if (Py_GETENV("PYTHONSHOWALLOCCOUNT")) {
dump_counts(stderr);
}
#endif

_PyDebug_PrintTotalRefs();
Expand Down