gh-124785: re-work fix so tracerefs test passes by nascheme · Pull Request #124808 · python/cpython · GitHub
Skip to content
Closed
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
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects.h
28 changes: 20 additions & 8 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,21 +1076,33 @@ def test_getallocatedblocks(self):
# about the underlying implementation: the function might
# return 0 or something greater.
self.assertGreaterEqual(a, 0)
try:
# While we could imagine a Python session where the number of
# multiple buffer objects would exceed the sharing of references,
# it is unlikely to happen in a normal test run.
self.assertLess(a, sys.gettotalrefcount())
except AttributeError:
# gettotalrefcount() not available
pass
gc.collect()
b = sys.getallocatedblocks()
self.assertLessEqual(b, a)
gc.collect()
c = sys.getallocatedblocks()
self.assertIn(c, range(b - 50, b + 50))

@unittest.skipUnless(hasattr(sys, "getallocatedblocks"),
"sys.getallocatedblocks unavailable on this build")
def test_getallocatedblocks_refcount(self):
# While we could imagine a Python session where the number of multiple
# buffer objects would exceed the sharing of references, it is unlikely
# to happen given that we run this in a subinterpreter.
code = """if 1:
import sys
num_blocks = sys.getallocatedblocks()
try:
total_refcnt = sys.gettotalrefcount()
except AttributeError:
pass
else:
if num_blocks > total_refcnt:
raise AssertionError('allocated blocks exceeds total refcnt')
"""
self.assertEqual(support.run_in_subinterp(code), 0,
'subinterp code failure, check stderr.')

def test_is_gil_enabled(self):
if support.Py_GIL_DISABLED:
self.assertIs(type(sys._is_gil_enabled()), bool)
Expand Down
81 changes: 77 additions & 4 deletions Objects/unicodeobject.c