Skip to content

gh-134248 test_getallocatedblocks pre-check to ignore immortalized strings #134871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
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
23 changes: 6 additions & 17 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,23 +1135,12 @@ def test_getallocatedblocks(self):
b = sys.getallocatedblocks()
self.assertLessEqual(b, a)
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.
#
# In free-threaded builds each code object owns an array of
# pointers to copies of the bytecode. When the number of
# code objects is a large fraction of the total number of
# references, this can cause the total number of allocated
# blocks to exceed the total number of references.
#
# For some reason, iOS seems to trigger the "unlikely to happen"
# case reliably under CI conditions. It's not clear why; but as
# this test is checking the behavior of getallocatedblock()
# under garbage collection, we can skip this pre-condition check
# for now. See GH-130384.
if not support.Py_GIL_DISABLED and not support.is_apple_mobile:
self.assertLess(a, sys.gettotalrefcount())
# The reported blocks will include immortalized strings, but the
# total ref count will not. This will sanity check that among all
# other objects (those eligible for garbage collection) there
# are more references being tracked than allocated blocks.
interned_immortal = sys.getunicodeinternedsize(_only_immortal=True)
self.assertLess(a - interned_immortal, sys.gettotalrefcount())
except AttributeError:
# gettotalrefcount() not available
pass
Expand Down
Loading